/* * Debug Store support * * This provides a low-level interface to the hardware's Debug Store * feature that is used for branch trace store (BTS) and * precise-event based sampling (PEBS). * * It manages: * - DS and BTS hardware configuration * - buffer overflow handling (to be done) * - buffer access * * It does not do: * - security checking (is the caller allowed to trace the task) * - buffer allocation (memory accounting) * * * Copyright (C) 2007-2009 Intel Corporation. * Markus Metzger <markus.t.metzger@intel.com>, 2007-2009 */#include<linux/kernel.h>#include<linux/string.h>#include<linux/errno.h>#include<linux/sched.h>#include<linux/slab.h>#include<linux/mm.h>#include<linux/trace_clock.h>#include<asm/ds.h>#include"ds_selftest.h"/* * The configuration for a particular DS hardware implementation: */structds_configuration{/* The name of the configuration: */constchar*name;/* The size of pointer-typed fields in DS, BTS, and PEBS: */unsignedcharsizeof_ptr_field;/* The size of a BTS/PEBS record in bytes: */unsignedcharsizeof_rec[2];/* The number of pebs counter reset values in the DS structure. */unsignedcharnr_counter_reset;/* Control bit-masks indexed by enum ds_feature: */unsignedlongctl[dsf_ctl_max];};staticstructds_configurationds_cfg__read_mostly;/* Maximal size of a DS configuration: */#define MAX_SIZEOF_DS 0x80/* Maximal size of a BTS record: */#define MAX_SIZEOF_BTS (3 * 8)/* BTS and PEBS buffer alignment: */#define DS_ALIGNMENT (1 << 3)/* Number of buffer pointers in DS: */#define NUM_DS_PTR_FIELDS 8/* Size of a pebs reset value in DS: */#define PEBS_RESET_FIELD_SIZE 8/* Mask of control bits in the DS MSR register: */#define BTS_CONTROL \ ( ds_cfg.ctl[dsf_bts] | \ ds_cfg.ctl[dsf_bts_kernel] | \ ds_cfg.ctl[dsf_bts_user] | \ ds_cfg.ctl[dsf_bts_overflow] )/* * A BTS or PEBS tracer. * * This holds the configuration of the tracer and serves as a handle * to identify tracers. */structds_tracer{/* The DS context (partially) owned by this tracer. */structds_context*context;/* The buffer provided on ds_request() and its size in bytes. */void*buffer;size_tsize;};structbts_tracer{/* The common DS part: */structds_tracerds;/* The trace including the DS configuration: */structbts_tracetrace;/* Buffer over