提交 5fca70ef 编写于 作者: D Daniel P. Berrange

perf: get rid of pointless virPerfGetEventAttr() method

The virPerfGetEventAttr method contains a totally pointless
loop. Remove it, verify the array size statically, and then
just use an array index to access the perf event.
Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
上级 c3d1df7b
......@@ -71,102 +71,109 @@ struct virPerf {
# include <linux/perf_event.h>
struct virPerfEventAttr {
int type;
unsigned int attrType;
unsigned long long attrConfig;
};
static struct virPerfEventAttr attrs[] = {
{.type = VIR_PERF_EVENT_CMT, .attrType = 0, .attrConfig = 1},
{.type = VIR_PERF_EVENT_MBMT, .attrType = 0, .attrConfig = 2},
{.type = VIR_PERF_EVENT_MBML, .attrType = 0, .attrConfig = 3},
{.type = VIR_PERF_EVENT_CPU_CYCLES,
.attrType = PERF_TYPE_HARDWARE,
.attrConfig = PERF_COUNT_HW_CPU_CYCLES},
{.type = VIR_PERF_EVENT_INSTRUCTIONS,
.attrType = PERF_TYPE_HARDWARE,
.attrConfig = PERF_COUNT_HW_INSTRUCTIONS},
{.type = VIR_PERF_EVENT_CACHE_REFERENCES,
.attrType = PERF_TYPE_HARDWARE,
.attrConfig = PERF_COUNT_HW_CACHE_REFERENCES},
{.type = VIR_PERF_EVENT_CACHE_MISSES,
.attrType = PERF_TYPE_HARDWARE,
.attrConfig = PERF_COUNT_HW_CACHE_MISSES},
{.type = VIR_PERF_EVENT_BRANCH_INSTRUCTIONS,
.attrType = PERF_TYPE_HARDWARE,
.attrConfig = PERF_COUNT_HW_BRANCH_INSTRUCTIONS},
{.type = VIR_PERF_EVENT_BRANCH_MISSES,
.attrType = PERF_TYPE_HARDWARE,
.attrConfig = PERF_COUNT_HW_BRANCH_MISSES},
{.type = VIR_PERF_EVENT_BUS_CYCLES,
.attrType = PERF_TYPE_HARDWARE,
.attrConfig = PERF_COUNT_HW_BUS_CYCLES},
{.type = VIR_PERF_EVENT_STALLED_CYCLES_FRONTEND,
.attrType = PERF_TYPE_HARDWARE,
.attrConfig = PERF_COUNT_HW_STALLED_CYCLES_FRONTEND},
{.type = VIR_PERF_EVENT_STALLED_CYCLES_BACKEND,
.attrType = PERF_TYPE_HARDWARE,
.attrConfig = PERF_COUNT_HW_STALLED_CYCLES_BACKEND},
{.type = VIR_PERF_EVENT_REF_CPU_CYCLES,
[VIR_PERF_EVENT_CMT] = {
.attrType = 0,
.attrConfig = 1
},
[VIR_PERF_EVENT_MBMT] = {
.attrType = 0,
.attrConfig = 2
},
[VIR_PERF_EVENT_MBML] {
.attrType = 0,
.attrConfig = 3
},
[VIR_PERF_EVENT_CPU_CYCLES] = {
.attrType = PERF_TYPE_HARDWARE,
.attrConfig = PERF_COUNT_HW_CPU_CYCLES
},
[VIR_PERF_EVENT_INSTRUCTIONS] = {
.attrType = PERF_TYPE_HARDWARE,
.attrConfig = PERF_COUNT_HW_INSTRUCTIONS
},
[VIR_PERF_EVENT_CACHE_REFERENCES] = {
.attrType = PERF_TYPE_HARDWARE,
.attrConfig = PERF_COUNT_HW_CACHE_REFERENCES
},
[VIR_PERF_EVENT_CACHE_MISSES] = {
.attrType = PERF_TYPE_HARDWARE,
.attrConfig = PERF_COUNT_HW_CACHE_MISSES
},
[VIR_PERF_EVENT_BRANCH_INSTRUCTIONS] = {
.attrType = PERF_TYPE_HARDWARE,
.attrConfig = PERF_COUNT_HW_BRANCH_INSTRUCTIONS
},
[VIR_PERF_EVENT_BRANCH_MISSES] = {
.attrType = PERF_TYPE_HARDWARE,
.attrConfig = PERF_COUNT_HW_BRANCH_MISSES
},
[VIR_PERF_EVENT_BUS_CYCLES] = {
.attrType = PERF_TYPE_HARDWARE,
.attrConfig = PERF_COUNT_HW_BUS_CYCLES
},
[VIR_PERF_EVENT_STALLED_CYCLES_FRONTEND] = {
.attrType = PERF_TYPE_HARDWARE,
.attrConfig = PERF_COUNT_HW_STALLED_CYCLES_FRONTEND
},
[VIR_PERF_EVENT_STALLED_CYCLES_BACKEND] = {
.attrType = PERF_TYPE_HARDWARE,
.attrConfig = PERF_COUNT_HW_STALLED_CYCLES_BACKEND
},
[VIR_PERF_EVENT_REF_CPU_CYCLES] = {
# ifdef PERF_COUNT_HW_REF_CPU_CYCLES
.attrType = PERF_TYPE_HARDWARE,
.attrConfig = PERF_COUNT_HW_REF_CPU_CYCLES
.attrType = PERF_TYPE_HARDWARE,
.attrConfig = PERF_COUNT_HW_REF_CPU_CYCLES
# else
.attrType = 0,
.attrConfig = 0,
.attrType = 0,
.attrConfig = 0,
# endif
},
{.type = VIR_PERF_EVENT_CPU_CLOCK,
.attrType = PERF_TYPE_SOFTWARE,
.attrConfig = PERF_COUNT_SW_CPU_CLOCK},
{.type = VIR_PERF_EVENT_TASK_CLOCK,
.attrType = PERF_TYPE_SOFTWARE,
.attrConfig = PERF_COUNT_SW_TASK_CLOCK},
{.type = VIR_PERF_EVENT_PAGE_FAULTS,
.attrType = PERF_TYPE_SOFTWARE,
.attrConfig = PERF_COUNT_SW_PAGE_FAULTS},
{.type = VIR_PERF_EVENT_CONTEXT_SWITCHES,
.attrType = PERF_TYPE_SOFTWARE,
.attrConfig = PERF_COUNT_SW_CONTEXT_SWITCHES},
{.type = VIR_PERF_EVENT_CPU_MIGRATIONS,
.attrType = PERF_TYPE_SOFTWARE,
.attrConfig = PERF_COUNT_SW_CPU_MIGRATIONS},
{.type = VIR_PERF_EVENT_PAGE_FAULTS_MIN,
.attrType = PERF_TYPE_SOFTWARE,
.attrConfig = PERF_COUNT_SW_PAGE_FAULTS_MIN},
{.type = VIR_PERF_EVENT_PAGE_FAULTS_MAJ,
.attrType = PERF_TYPE_SOFTWARE,
.attrConfig = PERF_COUNT_SW_PAGE_FAULTS_MAJ},
{.type = VIR_PERF_EVENT_ALIGNMENT_FAULTS,
.attrType = PERF_TYPE_SOFTWARE,
.attrConfig = PERF_COUNT_SW_ALIGNMENT_FAULTS},
{.type = VIR_PERF_EVENT_EMULATION_FAULTS,
.attrType = PERF_TYPE_SOFTWARE,
.attrConfig = PERF_COUNT_SW_EMULATION_FAULTS},
[VIR_PERF_EVENT_CPU_CLOCK] = {
.attrType = PERF_TYPE_SOFTWARE,
.attrConfig = PERF_COUNT_SW_CPU_CLOCK
},
[VIR_PERF_EVENT_TASK_CLOCK] = {
.attrType = PERF_TYPE_SOFTWARE,
.attrConfig = PERF_COUNT_SW_TASK_CLOCK
},
[VIR_PERF_EVENT_PAGE_FAULTS] = {
.attrType = PERF_TYPE_SOFTWARE,
.attrConfig = PERF_COUNT_SW_PAGE_FAULTS
},
[VIR_PERF_EVENT_CONTEXT_SWITCHES] = {
.attrType = PERF_TYPE_SOFTWARE,
.attrConfig = PERF_COUNT_SW_CONTEXT_SWITCHES
},
[VIR_PERF_EVENT_CPU_MIGRATIONS] = {
.attrType = PERF_TYPE_SOFTWARE,
.attrConfig = PERF_COUNT_SW_CPU_MIGRATIONS
},
[VIR_PERF_EVENT_PAGE_FAULTS_MIN] = {
.attrType = PERF_TYPE_SOFTWARE,
.attrConfig = PERF_COUNT_SW_PAGE_FAULTS_MIN
},
[VIR_PERF_EVENT_PAGE_FAULTS_MAJ] = {
.attrType = PERF_TYPE_SOFTWARE,
.attrConfig = PERF_COUNT_SW_PAGE_FAULTS_MAJ
},
[VIR_PERF_EVENT_ALIGNMENT_FAULTS] = {
.attrType = PERF_TYPE_SOFTWARE,
.attrConfig = PERF_COUNT_SW_ALIGNMENT_FAULTS
},
[VIR_PERF_EVENT_EMULATION_FAULTS] = {
.attrType = PERF_TYPE_SOFTWARE,
.attrConfig = PERF_COUNT_SW_EMULATION_FAULTS
},
};
verify(ARRAY_CARDINALITY(attrs) == VIR_PERF_EVENT_LAST);
typedef struct virPerfEventAttr *virPerfEventAttrPtr;
static virPerfEventAttrPtr
virPerfGetEventAttr(virPerfEventType type)
{
size_t i;
if (type >= VIR_PERF_EVENT_LAST) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Event '%d' is not supported"),
type);
return NULL;
}
for (i = 0; i < VIR_PERF_EVENT_LAST; i++) {
if (i == type)
return attrs + i;
}
return NULL;
}
static int
virPerfRdtAttrInit(void)
{
......@@ -224,9 +231,9 @@ virPerfEventEnable(virPerfPtr perf,
char *buf = NULL;
struct perf_event_attr attr;
virPerfEventPtr event = virPerfGetEvent(perf, type);
virPerfEventAttrPtr event_attr = virPerfGetEventAttr(type);
virPerfEventAttrPtr event_attr = &attrs[type];
if (!event || !event_attr)
if (!event)
return -1;
if (event->enabled)
......@@ -237,7 +244,7 @@ virPerfEventEnable(virPerfPtr perf,
type == VIR_PERF_EVENT_MBML)) {
virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED,
_("unable to enable host cpu perf event for %s"),
virPerfEventTypeToString(event->type));
virPerfEventTypeToString(type));
return -1;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册