From fd96d80a4642a569bc01d4bfd7b11ab60591165b Mon Sep 17 00:00:00 2001 From: Sathya Narayanan Date: Mon, 1 Feb 2016 09:14:24 -0800 Subject: [PATCH] Adding driver files --- drivers/osproject.c | 56 +++++++++++++++++++++++++++++++++++++++++++++ drivers/osproject_syscall.c | 23 +++++++++++++++++++ drivers/osproject_task.c | 34 +++++++++++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 drivers/osproject.c create mode 100644 drivers/osproject_syscall.c create mode 100644 drivers/osproject_task.c diff --git a/drivers/osproject.c b/drivers/osproject.c new file mode 100644 index 0000000..a768a0d --- /dev/null +++ b/drivers/osproject.c @@ -0,0 +1,56 @@ +/* + * * hello.c ­ The simplest kernel module. + * */ +#include + +#define ARMV7_PMNC_E (1 << 0) /* Enable all counters */ +#define ARMV7_PMNC_P (1 << 1) /* Reset all counters */ +#define ARMV7_PMNC_C (1 << 2) /* Cycle counter reset */ +#define ARMV7_PMNC_D (1 << 3) /* CCNT counts every 64th cpu cycle */ +#define ARMV7_PMNC_X (1 << 4) /* Export to ETM */ +#define ARMV7_PMNC_DP (1 << 5) /* Disable CCNT if non-invasive debug*/ +#define ARMV7_PMNC_N_SHIFT 11 /* Number of counters supported */ +#define ARMV7_PMNC_N_MASK 0x1f +#define ARMV7_PMNC_MASK 0x3f /* Mask for writable bits */ + +/*101b9173 +static u32 armv7_pmnc_read(void) +{ + u32 val; + asm volatile("mrc p15, 0, %0, c9, c12, 0" : "=r"(val)); + return val; +} + +static void armv7_pmnc_write(u32 val) +{ + val &= ARMV7_PMNC_MASK; + isb(); + asm volatile("mcr p15, 0, %0, c9, c12, 0" :: "r"(val)); +} +*/ + +int init_module() +{ + unsigned int regr; + unsigned int i; + unsigned int a, b; + + asm volatile("mrc p15, 0, %0, c9, c14, 0" : "=r" (regr)); + pr_info("regr: %x\n", regr); + + regr = 0; + for (i = 0; i < 1000; i++) { + asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (a)); + asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (b)); + regr += b - a; + pr_info("overhead: %u\n", b - a); + } + pr_info("Measurement overhead: %u\n", regr); + + + return 1; +} + +void cleanup_module() +{ +} diff --git a/drivers/osproject_syscall.c b/drivers/osproject_syscall.c new file mode 100644 index 0000000..4893cba --- /dev/null +++ b/drivers/osproject_syscall.c @@ -0,0 +1,23 @@ +#include +#include + +int init_module() +{ + unsigned int regr; + unsigned int i; + unsigned int a, b; + + asm volatile("mrc p15, 0, %0, c9, c14, 0" : "=r" (regr)); + pr_info("User access regr: %x\n", regr); + + asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (a)); + i = current->pid; + asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (b)); + + pr_info("PID: %u, Time for getpid: %u\n", i, b - a); + return 0; +} + +void cleanup_module() +{ +} diff --git a/drivers/osproject_task.c b/drivers/osproject_task.c new file mode 100644 index 0000000..112c9d2 --- /dev/null +++ b/drivers/osproject_task.c @@ -0,0 +1,34 @@ +#include + +int main() +{ + unsigned int regr; + unsigned int a, b; + unsigned int avg; + unsigned int pid; + + asm volatile("mrc p15, 0, %0, c9, c14, 0" : "=r" (regr)); + printf("regr: %x\n", regr); + + for (regr = 0; regr < 100; regr++) { + asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (a)); + asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (b)); + regr += (b - a); + } + + regr /= 100; + printf("Measurement overhead: %u\n", regr); + regr = 0; + while (regr < 100) { + asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (a)); + pid = fork(); + asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (b)); + printf("Time for fork: %u\n", b - a); + avg += (b - a); + regr++; + kill(pid, SIGKILL); + } + + printf("Fork avg: %u\n", avg/100); + return 1; +} -- 1.9.1