Skip to content
Snippets Groups Projects
Commit b481f271 authored by mihairenea's avatar mihairenea
Browse files

Call perf_event_kernel_counter() instead of perf_event_open(). Changed only to...

Call perf_event_kernel_counter() instead of perf_event_open(). Changed only to test includes, no functionality implemented.
parent d8373e7a
No related branches found
No related tags found
No related merge requests found
#include "perf_error_detection.h" #include "perf_error_detection.h"
#include <linux/smp.h>
//initialize perf event for new task //initialize perf event for new task
int init_perf_event(struct plan_entry plan_entry){ int init_perf_event(struct plan_entry plan_entry){
struct perf_event_attr pe; struct perf_event_attr pe;
struct sigaction sa; struct perf_event *event;
int fd;
//setting the overflow handler
memset(&sa, 0, sizeof(struct sigaction));
sa.sa_sigaction = overflow_handler;
sa.sa_flags = SA_SIGINFO;
if (sigaction( SIGIO, &sa, NULL) < 0) {
printk(KERN_WARNING "Error setting up perf overflow handler\n");
return -1;
}
//set perf_event_attr for init perf event //set perf_event_attr for init perf event
memset(&pe,0,sizeof(struct perf_event_attr)); memset(&pe,0,sizeof(struct perf_event_attr));
...@@ -32,39 +22,35 @@ int init_perf_event(struct plan_entry plan_entry){ ...@@ -32,39 +22,35 @@ int init_perf_event(struct plan_entry plan_entry){
//perf_event_open(perf_event_attr,pid,cpu,groupfd,flags=0) //perf_event_open(perf_event_attr,pid,cpu,groupfd,flags=0)
// cpu = -1 -> cpu indepented (assumed to be regulated by plan) // cpu = -1 -> cpu indepented (assumed to be regulated by plan)
fd=perf_event_open(&pe,plan_entry.task_struct->pid,-1,-1,0); event = perf_event_open(&pe, smp_processor_id());
if (fd<0) {
if (IS_ERR(event)) {
printk(KERN_WARNING "Error initializing perf event \n"); printk(KERN_WARNING "Error initializing perf event \n");
return -1; return -1;
} }
ioctl(fd, PERF_EVENT_IOC_RESET, 0);
if (ioctl(fd, PERF_EVENT_IOC_ENABLE, 0)<0) {
printk(KERN_WARNING "Error enabling perf event \n");
return -1;
}
return fd; return fd;
} }
//terminate perf event - return performance counter value //terminate perf event - return performance counter value
long long terminate_perf_event(int fd, u64 task_id){ long long terminate_perf_event(int fd, u64 task_id){
if (ioctl(fd, PERF_EVENT_IOC_DISABLE, 0) != 0){ // if (ioctl(fd, PERF_EVENT_IOC_DISABLE, 0) != 0){
printk(KERN_WARNING "could not disable perf event for task %llu",task_id); // printk(KERN_WARNING "could not disable perf event for task %llu",task_id);
} // }
long long count; long long count;
read(fd, &count, sizeof(long long)); // read(fd, &count, sizeof(long long));
close(fd); // close(fd);
return count; return count;
} }
//handle the perf overflow event -> task needed more instructions than planed //handle the perf overflow event -> task needed more instructions than planed
void overflow_handler(int signum,siginfo_t *oh, void *blah) { void overflow_handler(
struct perf_event *,
struct perf_sample_data *,
struct pt_regs *regs)
{
struct pb_rq *pb_rq; struct pb_rq *pb_rq;
int cpu; int cpu;
int fd; int fd;
...@@ -75,22 +61,17 @@ void overflow_handler(int signum,siginfo_t *oh, void *blah) { ...@@ -75,22 +61,17 @@ void overflow_handler(int signum,siginfo_t *oh, void *blah) {
printk(KERN_WARNING "task %llu ran too long\n",pb_rq->plan[pb_rq->c_entry].task_id); printk(KERN_WARNING "task %llu ran too long\n",pb_rq->plan[pb_rq->c_entry].task_id);
if (ioctl(fd, PERF_EVENT_IOC_DISABLE, 0) != 0){ // if (ioctl(fd, PERF_EVENT_IOC_DISABLE, 0) != 0){
printk(KERN_WARNING "could not disable perf event for cpu %d",cpu); // printk(KERN_WARNING "could not disable perf event for cpu %d",cpu);
} // }
} }
int perf_event_open(struct perf_event_attr *hw_event_uptr, pid_t pid, int cpu, int group_fd, unsigned long flags) { struct perf_event* perf_event_open(struct perf_event_attr *hw_event_uptr, int cpu)
mm_segment_t fs; {
int ret; return perf_event_create_kernel_counter(
hw_event_uptr,
fs = get_fs(); /* save previous value */ cpu,
NULL, /* per CPU */
set_fs (get_ds()); /* use kernel limit */ &overflow_handler,
NULL /* Was ist eigentlich context? */);
ret = syscall(__NR_perf_event_open,hw_event_uptr, pid, cpu, group_fd, flags);
set_fs(fs);
return ret;
} }
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
#include <linux/perf_event.h> #include <linux/perf_event.h>
//#include <linux/sched.h> //#include <linux/sched.h>
#include "sched.h" #include "sched.h"
#include "../../include/linux/signal.h" //#include "../../include/linux/signal.h"
#include <linux/ioctl.h> //#include <linux/ioctl.h>
#include "../../include/linux/fs.h" //#include "../../include/linux/fs.h"
//#include <include/linux/smp.h> //#include <include/linux/smp.h>
#endif #endif
...@@ -14,6 +14,9 @@ int init_perf_event(struct plan_entry); ...@@ -14,6 +14,9 @@ int init_perf_event(struct plan_entry);
long long terminate_perf_event(int fd, u64 task_id); long long terminate_perf_event(int fd, u64 task_id);
void overflow_handler(int,siginfo_t *oh, void *blah); void overflow_handler(
struct perf_event *,
struct perf_sample_data *,
struct pt_regs *regs);
int perf_event_open(struct perf_event_attr *hw_event_uptr, pid_t, int, int, unsigned long); struct perf_event *perf_event_open(struct perf_event_attr *hw_event_uptr, int);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment