Skip to content

Commit bf8f9e4

Browse files
committed
drm/sti: add debugfs fps_show/fps_get mechanism for planes
Display fps on demand for each used plane: cat /sys/kernel/debug/dri/0/fps_get Display fps in live in the console for each used plane: echo 255 > /sys/kernel/debug/dri/0/fps_show Signed-off-by: Vincent Abriou <vincent.abriou@st.com> Reviewed-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
1 parent b514bee commit bf8f9e4

File tree

6 files changed

+216
-7
lines changed

6 files changed

+216
-7
lines changed

drivers/gpu/drm/sti/sti_cursor.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@ static void sti_cursor_atomic_update(struct drm_plane *drm_plane,
306306
writel(cursor->clut_paddr, cursor->regs + CUR_CML);
307307
writel(CUR_CTL_CLUT_UPDATE, cursor->regs + CUR_CTL);
308308

309+
sti_plane_update_fps(plane, true, false);
310+
309311
plane->status = STI_PLANE_UPDATED;
310312
}
311313

drivers/gpu/drm/sti/sti_drv.c

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "sti_crtc.h"
2222
#include "sti_drv.h"
23+
#include "sti_plane.h"
2324

2425
#define DRIVER_NAME "sti"
2526
#define DRIVER_DESC "STMicroelectronics SoC DRM"
@@ -30,6 +31,130 @@
3031
#define STI_MAX_FB_HEIGHT 4096
3132
#define STI_MAX_FB_WIDTH 4096
3233

34+
static int sti_drm_fps_get(void *data, u64 *val)
35+
{
36+
struct drm_device *drm_dev = data;
37+
struct drm_plane *p;
38+
unsigned int i = 0;
39+
40+
*val = 0;
41+
list_for_each_entry(p, &drm_dev->mode_config.plane_list, head) {
42+
struct sti_plane *plane = to_sti_plane(p);
43+
44+
*val |= plane->fps_info.output << i;
45+
i++;
46+
}
47+
48+
return 0;
49+
}
50+
51+
static int sti_drm_fps_set(void *data, u64 val)
52+
{
53+
struct drm_device *drm_dev = data;
54+
struct drm_plane *p;
55+
unsigned int i = 0;
56+
57+
list_for_each_entry(p, &drm_dev->mode_config.plane_list, head) {
58+
struct sti_plane *plane = to_sti_plane(p);
59+
60+
plane->fps_info.output = (val >> i) & 1;
61+
i++;
62+
}
63+
64+
return 0;
65+
}
66+
67+
DEFINE_SIMPLE_ATTRIBUTE(sti_drm_fps_fops,
68+
sti_drm_fps_get, sti_drm_fps_set, "%llu\n");
69+
70+
static int sti_drm_fps_dbg_show(struct seq_file *s, void *data)
71+
{
72+
struct drm_info_node *node = s->private;
73+
struct drm_device *dev = node->minor->dev;
74+
struct drm_plane *p;
75+
int ret;
76+
77+
ret = mutex_lock_interruptible(&dev->struct_mutex);
78+
if (ret)
79+
return ret;
80+
81+
list_for_each_entry(p, &dev->mode_config.plane_list, head) {
82+
struct sti_plane *plane = to_sti_plane(p);
83+
84+
seq_printf(s, "%s%s\n",
85+
plane->fps_info.fps_str,
86+
plane->fps_info.fips_str);
87+
}
88+
89+
mutex_unlock(&dev->struct_mutex);
90+
return 0;
91+
}
92+
93+
static struct drm_info_list sti_drm_dbg_list[] = {
94+
{"fps_get", sti_drm_fps_dbg_show, 0},
95+
};
96+
97+
static int sti_drm_debugfs_create(struct dentry *root,
98+
struct drm_minor *minor,
99+
const char *name,
100+
const struct file_operations *fops)
101+
{
102+
struct drm_device *dev = minor->dev;
103+
struct drm_info_node *node;
104+
struct dentry *ent;
105+
106+
ent = debugfs_create_file(name, S_IRUGO | S_IWUSR, root, dev, fops);
107+
if (IS_ERR(ent))
108+
return PTR_ERR(ent);
109+
110+
node = kmalloc(sizeof(*node), GFP_KERNEL);
111+
if (!node) {
112+
debugfs_remove(ent);
113+
return -ENOMEM;
114+
}
115+
116+
node->minor = minor;
117+
node->dent = ent;
118+
node->info_ent = (void *)fops;
119+
120+
mutex_lock(&minor->debugfs_lock);
121+
list_add(&node->list, &minor->debugfs_list);
122+
mutex_unlock(&minor->debugfs_lock);
123+
124+
return 0;
125+
}
126+
127+
static int sti_drm_dbg_init(struct drm_minor *minor)
128+
{
129+
int ret;
130+
131+
ret = drm_debugfs_create_files(sti_drm_dbg_list,
132+
ARRAY_SIZE(sti_drm_dbg_list),
133+
minor->debugfs_root, minor);
134+
if (ret)
135+
goto err;
136+
137+
ret = sti_drm_debugfs_create(minor->debugfs_root, minor, "fps_show",
138+
&sti_drm_fps_fops);
139+
if (ret)
140+
goto err;
141+
142+
DRM_INFO("%s: debugfs installed\n", DRIVER_NAME);
143+
return 0;
144+
err:
145+
DRM_ERROR("%s: cannot install debugfs\n", DRIVER_NAME);
146+
return ret;
147+
}
148+
149+
void sti_drm_dbg_cleanup(struct drm_minor *minor)
150+
{
151+
drm_debugfs_remove_files(sti_drm_dbg_list,
152+
ARRAY_SIZE(sti_drm_dbg_list), minor);
153+
154+
drm_debugfs_remove_files((struct drm_info_list *)&sti_drm_fps_fops,
155+
1, minor);
156+
}
157+
33158
static void sti_atomic_schedule(struct sti_private *private,
34159
struct drm_atomic_state *state)
35160
{
@@ -215,6 +340,9 @@ static struct drm_driver sti_driver = {
215340
.gem_prime_vunmap = drm_gem_cma_prime_vunmap,
216341
.gem_prime_mmap = drm_gem_cma_prime_mmap,
217342

343+
.debugfs_init = sti_drm_dbg_init,
344+
.debugfs_cleanup = sti_drm_dbg_cleanup,
345+
218346
.name = DRIVER_NAME,
219347
.desc = DRIVER_DESC,
220348
.date = DRIVER_DATE,

drivers/gpu/drm/sti/sti_gdp.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,8 @@ static void sti_gdp_atomic_update(struct drm_plane *drm_plane,
850850
}
851851

852852
end:
853+
sti_plane_update_fps(plane, true, false);
854+
853855
plane->status = STI_PLANE_UPDATED;
854856
}
855857

drivers/gpu/drm/sti/sti_hqvdp.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,6 @@ struct sti_hqvdp_cmd {
326326
* @reset: reset control
327327
* @vtg_nb: notifier to handle VTG Vsync
328328
* @btm_field_pending: is there any bottom field (interlaced frame) to display
329-
* @curr_field_count: number of field updates
330-
* @last_field_count: number of field updates since last fps measure
331329
* @hqvdp_cmd: buffer of commands
332330
* @hqvdp_cmd_paddr: physical address of hqvdp_cmd
333331
* @vtg: vtg for main data path
@@ -343,8 +341,6 @@ struct sti_hqvdp {
343341
struct reset_control *reset;
344342
struct notifier_block vtg_nb;
345343
bool btm_field_pending;
346-
unsigned int curr_field_count;
347-
unsigned int last_field_count;
348344
void *hqvdp_cmd;
349345
dma_addr_t hqvdp_cmd_paddr;
350346
struct sti_vtg *vtg;
@@ -836,11 +832,12 @@ int sti_hqvdp_vtg_cb(struct notifier_block *nb, unsigned long evt, void *data)
836832
writel(hqvdp->hqvdp_cmd_paddr + btm_cmd_offset,
837833
hqvdp->regs + HQVDP_MBX_NEXT_CMD);
838834

839-
hqvdp->curr_field_count++;
840835
hqvdp->btm_field_pending = false;
841836

842837
dev_dbg(hqvdp->dev, "%s Posted command:0x%x\n",
843838
__func__, hqvdp->hqvdp_cmd_paddr);
839+
840+
sti_plane_update_fps(&hqvdp->plane, false, true);
844841
}
845842

846843
return 0;
@@ -1204,15 +1201,15 @@ static void sti_hqvdp_atomic_update(struct drm_plane *drm_plane,
12041201
writel(hqvdp->hqvdp_cmd_paddr + cmd_offset,
12051202
hqvdp->regs + HQVDP_MBX_NEXT_CMD);
12061203

1207-
hqvdp->curr_field_count++;
1208-
12091204
/* Interlaced : get ready to display the bottom field at next Vsync */
12101205
if (fb->flags & DRM_MODE_FB_INTERLACED)
12111206
hqvdp->btm_field_pending = true;
12121207

12131208
dev_dbg(hqvdp->dev, "%s Posted command:0x%x\n",
12141209
__func__, hqvdp->hqvdp_cmd_paddr + cmd_offset);
12151210

1211+
sti_plane_update_fps(plane, true, true);
1212+
12161213
plane->status = STI_PLANE_UPDATED;
12171214
}
12181215

drivers/gpu/drm/sti/sti_plane.c

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,69 @@ const char *sti_plane_to_str(struct sti_plane *plane)
4343
}
4444
}
4545

46+
#define STI_FPS_INTERVAL_MS 3000
47+
48+
static int sti_plane_timespec_ms_diff(struct timespec lhs, struct timespec rhs)
49+
{
50+
struct timespec tmp_ts = timespec_sub(lhs, rhs);
51+
u64 tmp_ns = (u64)timespec_to_ns(&tmp_ts);
52+
53+
do_div(tmp_ns, NSEC_PER_MSEC);
54+
55+
return (u32)tmp_ns;
56+
}
57+
58+
void sti_plane_update_fps(struct sti_plane *plane,
59+
bool new_frame,
60+
bool new_field)
61+
{
62+
struct timespec now;
63+
struct sti_fps_info *fps;
64+
int fpks, fipks, ms_since_last, num_frames, num_fields;
65+
66+
getrawmonotonic(&now);
67+
68+
/* Compute number of frame updates */
69+
fps = &plane->fps_info;
70+
71+
if (new_field)
72+
fps->curr_field_counter++;
73+
74+
/* do not perform fps calcul if new_frame is false */
75+
if (!new_frame)
76+
return;
77+
78+
fps->curr_frame_counter++;
79+
ms_since_last = sti_plane_timespec_ms_diff(now, fps->last_timestamp);
80+
num_frames = fps->curr_frame_counter - fps->last_frame_counter;
81+
82+
if (num_frames <= 0 || ms_since_last < STI_FPS_INTERVAL_MS)
83+
return;
84+
85+
fps->last_timestamp = now;
86+
fps->last_frame_counter = fps->curr_frame_counter;
87+
fpks = (num_frames * 1000000) / ms_since_last;
88+
snprintf(plane->fps_info.fps_str, FPS_LENGTH, "%-6s @ %d.%.3d fps",
89+
sti_plane_to_str(plane), fpks / 1000, fpks % 1000);
90+
91+
if (fps->curr_field_counter) {
92+
/* Compute number of field updates */
93+
num_fields = fps->curr_field_counter - fps->last_field_counter;
94+
fps->last_field_counter = fps->curr_field_counter;
95+
fipks = (num_fields * 1000000) / ms_since_last;
96+
snprintf(plane->fps_info.fips_str,
97+
FPS_LENGTH, " - %d.%.3d field/sec",
98+
fipks / 1000, fipks % 1000);
99+
} else {
100+
plane->fps_info.fips_str[0] = '\0';
101+
}
102+
103+
if (fps->output)
104+
DRM_INFO("%s%s\n",
105+
plane->fps_info.fps_str,
106+
plane->fps_info.fips_str);
107+
}
108+
46109
static void sti_plane_destroy(struct drm_plane *drm_plane)
47110
{
48111
DRM_DEBUG_DRIVER("\n");

drivers/gpu/drm/sti/sti_plane.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,39 @@ enum sti_plane_status {
5050
STI_PLANE_DISABLED,
5151
};
5252

53+
#define FPS_LENGTH 64
54+
struct sti_fps_info {
55+
bool output;
56+
unsigned int curr_frame_counter;
57+
unsigned int last_frame_counter;
58+
unsigned int curr_field_counter;
59+
unsigned int last_field_counter;
60+
struct timespec last_timestamp;
61+
char fps_str[FPS_LENGTH];
62+
char fips_str[FPS_LENGTH];
63+
};
64+
5365
/**
5466
* STI plane structure
5567
*
5668
* @plane: drm plane it is bound to (if any)
5769
* @desc: plane type & id
5870
* @status: to know the status of the plane
5971
* @zorder: plane z-order
72+
* @fps_info: frame per second info
6073
*/
6174
struct sti_plane {
6275
struct drm_plane drm_plane;
6376
enum sti_plane_desc desc;
6477
enum sti_plane_status status;
6578
int zorder;
79+
struct sti_fps_info fps_info;
6680
};
6781

6882
const char *sti_plane_to_str(struct sti_plane *plane);
83+
void sti_plane_update_fps(struct sti_plane *plane,
84+
bool new_frame,
85+
bool new_field);
6986
void sti_plane_init_property(struct sti_plane *plane,
7087
enum drm_plane_type type);
7188
#endif

0 commit comments

Comments
 (0)