aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/oprofile/cpu_buffer.c
diff options
context:
space:
mode:
authorBarry Kasindorf <barry.kasindorf@amd.com>2008-07-22 15:08:54 -0400
committerIngo Molnar <mingo@elte.hu>2008-07-26 05:48:04 -0400
commit345c25730d085c45622ac779da4dbd97dc3a10fe (patch)
tree12f31ee55b97ef9604b37990e05c523178c32901 /drivers/oprofile/cpu_buffer.c
parentee648bc77f11b57d15a68d336fc30e343198f893 (diff)
x86/oprofile: add IBS support for AMD CPUs, IBS buffer handling routines
This patchset supports the new profiling hardware available in the latest AMD CPUs in the oProfile driver. Signed-off-by: Barry Kasindorf <barry.kasindorf@amd.com> Signed-off-by: Robert Richter <robert.richter@amd.com> Cc: oprofile-list <oprofile-list@lists.sourceforge.net> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'drivers/oprofile/cpu_buffer.c')
-rw-r--r--drivers/oprofile/cpu_buffer.c68
1 files changed, 67 insertions, 1 deletions
diff --git a/drivers/oprofile/cpu_buffer.c b/drivers/oprofile/cpu_buffer.c
index 2450b3a393ff..c9ac4e156918 100644
--- a/drivers/oprofile/cpu_buffer.c
+++ b/drivers/oprofile/cpu_buffer.c
@@ -5,6 +5,7 @@
5 * @remark Read the file COPYING 5 * @remark Read the file COPYING
6 * 6 *
7 * @author John Levon <levon@movementarian.org> 7 * @author John Levon <levon@movementarian.org>
8 * @author Barry Kasindorf <barry.kasindorf@amd.com>
8 * 9 *
9 * Each CPU has a local buffer that stores PC value/event 10 * Each CPU has a local buffer that stores PC value/event
10 * pairs. We also log context switches when we notice them. 11 * pairs. We also log context switches when we notice them.
@@ -207,7 +208,7 @@ static int log_sample(struct oprofile_cpu_buffer * cpu_buf, unsigned long pc,
207 return 1; 208 return 1;
208} 209}
209 210
210static int oprofile_begin_trace(struct oprofile_cpu_buffer * cpu_buf) 211static int oprofile_begin_trace(struct oprofile_cpu_buffer *cpu_buf)
211{ 212{
212 if (nr_available_slots(cpu_buf) < 4) { 213 if (nr_available_slots(cpu_buf) < 4) {
213 cpu_buf->sample_lost_overflow++; 214 cpu_buf->sample_lost_overflow++;
@@ -252,6 +253,71 @@ void oprofile_add_sample(struct pt_regs * const regs, unsigned long event)
252 oprofile_add_ext_sample(pc, regs, event, is_kernel); 253 oprofile_add_ext_sample(pc, regs, event, is_kernel);
253} 254}
254 255
256#define MAX_IBS_SAMPLE_SIZE 14
257static int log_ibs_sample(struct oprofile_cpu_buffer *cpu_buf,
258 unsigned long pc, int is_kernel, unsigned int *ibs, int ibs_code)
259{
260 struct task_struct *task;
261
262 cpu_buf->sample_received++;
263
264 if (nr_available_slots(cpu_buf) < MAX_IBS_SAMPLE_SIZE) {
265 cpu_buf->sample_lost_overflow++;
266 return 0;
267 }
268
269 is_kernel = !!is_kernel;
270
271 /* notice a switch from user->kernel or vice versa */
272 if (cpu_buf->last_is_kernel != is_kernel) {
273 cpu_buf->last_is_kernel = is_kernel;
274 add_code(cpu_buf, is_kernel);
275 }
276
277 /* notice a task switch */
278 if (!is_kernel) {
279 task = current;
280
281 if (cpu_buf->last_task != task) {
282 cpu_buf->last_task = task;
283 add_code(cpu_buf, (unsigned long)task);
284 }
285 }
286
287 add_code(cpu_buf, ibs_code);
288 add_sample(cpu_buf, ibs[0], ibs[1]);
289 add_sample(cpu_buf, ibs[2], ibs[3]);
290 add_sample(cpu_buf, ibs[4], ibs[5]);
291
292 if (ibs_code == IBS_OP_BEGIN) {
293 add_sample(cpu_buf, ibs[6], ibs[7]);
294 add_sample(cpu_buf, ibs[8], ibs[9]);
295 add_sample(cpu_buf, ibs[10], ibs[11]);
296 }
297
298 return 1;
299}
300
301void oprofile_add_ibs_sample(struct pt_regs *const regs,
302 unsigned int * const ibs_sample, u8 code)
303{
304 int is_kernel = !user_mode(regs);
305 unsigned long pc = profile_pc(regs);
306
307 struct oprofile_cpu_buffer *cpu_buf =
308 &per_cpu(cpu_buffer, smp_processor_id());
309
310 if (!backtrace_depth) {
311 log_ibs_sample(cpu_buf, pc, is_kernel, ibs_sample, code);
312 return;
313 }
314
315 /* if log_sample() fails we can't backtrace since we lost the source
316 * of this event */
317 if (log_ibs_sample(cpu_buf, pc, is_kernel, ibs_sample, code))
318 oprofile_ops.backtrace(regs, backtrace_depth);
319}
320
255void oprofile_add_pc(unsigned long pc, int is_kernel, unsigned long event) 321void oprofile_add_pc(unsigned long pc, int is_kernel, unsigned long event)
256{ 322{
257 struct oprofile_cpu_buffer *cpu_buf = &__get_cpu_var(cpu_buffer); 323 struct oprofile_cpu_buffer *cpu_buf = &__get_cpu_var(cpu_buffer);
>struct device_attribute *attr, const char *buf, size_t size) { struct omap_dss_device *dssdev = to_dss_device(dev); struct omap_video_timings t; int r, found; if (!dssdev->driver->set_timings || !dssdev->driver->check_timings) return -ENOENT; found = 0; #ifdef CONFIG_OMAP2_DSS_VENC if (strncmp("pal", buf, 3) == 0) { t = omap_dss_pal_timings; found = 1; } else if (strncmp("ntsc", buf, 4) == 0) { t = omap_dss_ntsc_timings; found = 1; } #endif if (!found && sscanf(buf, "%u,%hu/%hu/%hu/%hu,%hu/%hu/%hu/%hu", &t.pixel_clock, &t.x_res, &t.hfp, &t.hbp, &t.hsw, &t.y_res, &t.vfp, &t.vbp, &t.vsw) != 9) return -EINVAL; r = dssdev->driver->check_timings(dssdev, &t); if (r) return r; dssdev->driver->set_timings(dssdev, &t); return size; } static ssize_t display_rotate_show(struct device *dev, struct device_attribute *attr, char *buf) { struct omap_dss_device *dssdev = to_dss_device(dev); int rotate; if (!dssdev->driver->get_rotate) return -ENOENT; rotate = dssdev->driver->get_rotate(dssdev); return snprintf(buf, PAGE_SIZE, "%u\n", rotate); } static ssize_t display_rotate_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { struct omap_dss_device *dssdev = to_dss_device(dev); unsigned long rot; int r; if (!dssdev->driver->set_rotate || !dssdev->driver->get_rotate) return -ENOENT; rot = simple_strtoul(buf, NULL, 0); r = dssdev->driver->set_rotate(dssdev, rot); if (r) return r; return size; } static ssize_t display_mirror_show(struct device *dev, struct device_attribute *attr, char *buf) { struct omap_dss_device *dssdev = to_dss_device(dev); int mirror; if (!dssdev->driver->get_mirror) return -ENOENT; mirror = dssdev->driver->get_mirror(dssdev); return snprintf(buf, PAGE_SIZE, "%u\n", mirror); } static ssize_t display_mirror_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { struct omap_dss_device *dssdev = to_dss_device(dev); unsigned long mirror; int r; if (!dssdev->driver->set_mirror || !dssdev->driver->get_mirror) return -ENOENT; mirror = simple_strtoul(buf, NULL, 0); r = dssdev->driver->set_mirror(dssdev, mirror); if (r) return r; return size; } static ssize_t display_wss_show(struct device *dev, struct device_attribute *attr, char *buf) { struct omap_dss_device *dssdev = to_dss_device(dev); unsigned int wss; if (!dssdev->driver->get_wss) return -ENOENT; wss = dssdev->driver->get_wss(dssdev); return snprintf(buf, PAGE_SIZE, "0x%05x\n", wss); } static ssize_t display_wss_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { struct omap_dss_device *dssdev = to_dss_device(dev); unsigned long wss; int r; if (!dssdev->driver->get_wss || !dssdev->driver->set_wss) return -ENOENT; if (strict_strtoul(buf, 0, &wss)) return -EINVAL; if (wss > 0xfffff) return -EINVAL; r = dssdev->driver->set_wss(dssdev, wss); if (r) return r; return size; } static DEVICE_ATTR(enabled, S_IRUGO|S_IWUSR, display_enabled_show, display_enabled_store); static DEVICE_ATTR(update_mode, S_IRUGO|S_IWUSR, display_upd_mode_show, display_upd_mode_store); static DEVICE_ATTR(tear_elim, S_IRUGO|S_IWUSR, display_tear_show, display_tear_store); static DEVICE_ATTR(timings, S_IRUGO|S_IWUSR, display_timings_show, display_timings_store); static DEVICE_ATTR(rotate, S_IRUGO|S_IWUSR, display_rotate_show, display_rotate_store); static DEVICE_ATTR(mirror, S_IRUGO|S_IWUSR, display_mirror_show, display_mirror_store); static DEVICE_ATTR(wss, S_IRUGO|S_IWUSR, display_wss_show, display_wss_store); static struct device_attribute *display_sysfs_attrs[] = { &dev_attr_enabled, &dev_attr_update_mode, &dev_attr_tear_elim, &dev_attr_timings, &dev_attr_rotate, &dev_attr_mirror, &dev_attr_wss, NULL }; void omapdss_default_get_resolution(struct omap_dss_device *dssdev, u16 *xres, u16 *yres) { *xres = dssdev->panel.timings.x_res; *yres = dssdev->panel.timings.y_res; } EXPORT_SYMBOL(omapdss_default_get_resolution); void default_get_overlay_fifo_thresholds(enum omap_plane plane, u32 fifo_size, enum omap_burst_size *burst_size, u32 *fifo_low, u32 *fifo_high) { unsigned burst_size_bytes; *burst_size = OMAP_DSS_BURST_16x32; burst_size_bytes = 16 * 32 / 8; *fifo_high = fifo_size - 1; *fifo_low = fifo_size - burst_size_bytes; } int omapdss_default_get_recommended_bpp(struct omap_dss_device *dssdev) { switch (dssdev->type) { case OMAP_DISPLAY_TYPE_DPI: if (dssdev->phy.dpi.data_lines == 24) return 24; else return 16; case OMAP_DISPLAY_TYPE_DBI: case OMAP_DISPLAY_TYPE_DSI: if (dssdev->ctrl.pixel_size == 24) return 24; else return 16; case OMAP_DISPLAY_TYPE_VENC: case OMAP_DISPLAY_TYPE_SDI: case OMAP_DISPLAY_TYPE_HDMI: return 24; default: BUG(); } } EXPORT_SYMBOL(omapdss_default_get_recommended_bpp); /* Checks if replication logic should be used. Only use for active matrix, * when overlay is in RGB12U or RGB16 mode, and LCD interface is * 18bpp or 24bpp */ bool dss_use_replication(struct omap_dss_device *dssdev, enum omap_color_mode mode) { int bpp; if (mode != OMAP_DSS_COLOR_RGB12U && mode != OMAP_DSS_COLOR_RGB16) return false; if (dssdev->type == OMAP_DISPLAY_TYPE_DPI && (dssdev->panel.config & OMAP_DSS_LCD_TFT) == 0) return false; switch (dssdev->type) { case OMAP_DISPLAY_TYPE_DPI: bpp = dssdev->phy.dpi.data_lines; break; case OMAP_DISPLAY_TYPE_HDMI: case OMAP_DISPLAY_TYPE_VENC: case OMAP_DISPLAY_TYPE_SDI: bpp = 24; break; case OMAP_DISPLAY_TYPE_DBI: case OMAP_DISPLAY_TYPE_DSI: bpp = dssdev->ctrl.pixel_size; break; default: BUG(); } return bpp > 16; } void dss_init_device(struct platform_device *pdev, struct omap_dss_device *dssdev) { struct device_attribute *attr; int i; int r; switch (dssdev->type) { #ifdef CONFIG_OMAP2_DSS_DPI case OMAP_DISPLAY_TYPE_DPI: r = dpi_init_display(dssdev); break; #endif #ifdef CONFIG_OMAP2_DSS_RFBI case OMAP_DISPLAY_TYPE_DBI: r = rfbi_init_display(dssdev); break; #endif #ifdef CONFIG_OMAP2_DSS_VENC case OMAP_DISPLAY_TYPE_VENC: r = venc_init_display(dssdev); break; #endif #ifdef CONFIG_OMAP2_DSS_SDI case OMAP_DISPLAY_TYPE_SDI: r = sdi_init_display(dssdev); break; #endif #ifdef CONFIG_OMAP2_DSS_DSI case OMAP_DISPLAY_TYPE_DSI: r = dsi_init_display(dssdev); break; #endif case OMAP_DISPLAY_TYPE_HDMI: r = hdmi_init_display(dssdev); break; default: DSSERR("Support for display '%s' not compiled in.\n", dssdev->name); return; } if (r) { DSSERR("failed to init display %s\n", dssdev->name); return; } /* create device sysfs files */ i = 0; while ((attr = display_sysfs_attrs[i++]) != NULL) { r = device_create_file(&dssdev->dev, attr); if (r) DSSERR("failed to create sysfs file\n"); } /* create display? sysfs links */ r = sysfs_create_link(&pdev->dev.kobj, &dssdev->dev.kobj, dev_name(&dssdev->dev)); if (r) DSSERR("failed to create sysfs display link\n"); } void dss_uninit_device(struct platform_device *pdev, struct omap_dss_device *dssdev) { struct device_attribute *attr; int i = 0; sysfs_remove_link(&pdev->dev.kobj, dev_name(&dssdev->dev)); while ((attr = display_sysfs_attrs[i++]) != NULL) device_remove_file(&dssdev->dev, attr); if (dssdev->manager) dssdev->manager->unset_device(dssdev->manager); } static int dss_suspend_device(struct device *dev, void *data) { int r; struct omap_dss_device *dssdev = to_dss_device(dev); if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) { dssdev->activate_after_resume = false; return 0; } if (!dssdev->driver->suspend) { DSSERR("display '%s' doesn't implement suspend\n", dssdev->name); return -ENOSYS; } r = dssdev->driver->suspend(dssdev); if (r) return r; dssdev->activate_after_resume = true; return 0; } int dss_suspend_all_devices(void) { int r; struct bus_type *bus = dss_get_bus(); r = bus_for_each_dev(bus, NULL, NULL, dss_suspend_device); if (r) { /* resume all displays that were suspended */ dss_resume_all_devices(); return r; } return 0; } static int dss_resume_device(struct device *dev, void *data) { int r; struct omap_dss_device *dssdev = to_dss_device(dev); if (dssdev->activate_after_resume && dssdev->driver->resume) { r = dssdev->driver->resume(dssdev); if (r) return r; } dssdev->activate_after_resume = false; return 0; } int dss_resume_all_devices(void) { struct bus_type *bus = dss_get_bus(); return bus_for_each_dev(bus, NULL, NULL, dss_resume_device); } static int dss_disable_device(struct device *dev, void *data) { struct omap_dss_device *dssdev = to_dss_device(dev); if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) dssdev->driver->disable(dssdev); return 0; } void dss_disable_all_devices(void) { struct bus_type *bus = dss_get_bus(); bus_for_each_dev(bus, NULL, NULL, dss_disable_device); } void omap_dss_get_device(struct omap_dss_device *dssdev) { get_device(&dssdev->dev); } EXPORT_SYMBOL(omap_dss_get_device); void omap_dss_put_device(struct omap_dss_device *dssdev) { put_device(&dssdev->dev); } EXPORT_SYMBOL(omap_dss_put_device); /* ref count of the found device is incremented. ref count * of from-device is decremented. */ struct omap_dss_device *omap_dss_get_next_device(struct omap_dss_device *from) { struct device *dev; struct device *dev_start = NULL; struct omap_dss_device *dssdev = NULL; int match(struct device *dev, void *data) { return 1; } if (from) dev_start = &from->dev; dev = bus_find_device(dss_get_bus(), dev_start, NULL, match); if (dev) dssdev = to_dss_device(dev); if (from) put_device(&from->dev); return dssdev; } EXPORT_SYMBOL(omap_dss_get_next_device); struct omap_dss_device *omap_dss_find_device(void *data, int (*match)(struct omap_dss_device *dssdev, void *data)) { struct omap_dss_device *dssdev = NULL; while ((dssdev = omap_dss_get_next_device(dssdev)) != NULL) { if (match(dssdev, data)) return dssdev; } return NULL; } EXPORT_SYMBOL(omap_dss_find_device); int omap_dss_start_device(struct omap_dss_device *dssdev) { if (!dssdev->driver) { DSSDBG("no driver\n"); return -ENODEV; } if (!try_module_get(dssdev->dev.driver->owner)) { return -ENODEV; } return 0; } EXPORT_SYMBOL(omap_dss_start_device); void omap_dss_stop_device(struct omap_dss_device *dssdev) { module_put(dssdev->dev.driver->owner); } EXPORT_SYMBOL(omap_dss_stop_device);