Commit fd96d80a4642a569bc01d4bfd7b11ab60591165b

Authored by Sathya Narayanan
1 parent 17110dd658
Exists in master

Adding driver files

Showing 3 changed files with 113 additions and 0 deletions Side-by-side Diff

drivers/osproject.c View file @ fd96d80
  1 +/*
  2 + * * hello.c ­ The simplest kernel module.
  3 + * */
  4 +#include <linux/module.h>
  5 +
  6 +#define ARMV7_PMNC_E (1 << 0) /* Enable all counters */
  7 +#define ARMV7_PMNC_P (1 << 1) /* Reset all counters */
  8 +#define ARMV7_PMNC_C (1 << 2) /* Cycle counter reset */
  9 +#define ARMV7_PMNC_D (1 << 3) /* CCNT counts every 64th cpu cycle */
  10 +#define ARMV7_PMNC_X (1 << 4) /* Export to ETM */
  11 +#define ARMV7_PMNC_DP (1 << 5) /* Disable CCNT if non-invasive debug*/
  12 +#define ARMV7_PMNC_N_SHIFT 11 /* Number of counters supported */
  13 +#define ARMV7_PMNC_N_MASK 0x1f
  14 +#define ARMV7_PMNC_MASK 0x3f /* Mask for writable bits */
  15 +
  16 +/*101b9173
  17 +static u32 armv7_pmnc_read(void)
  18 +{
  19 + u32 val;
  20 + asm volatile("mrc p15, 0, %0, c9, c12, 0" : "=r"(val));
  21 + return val;
  22 +}
  23 +
  24 +static void armv7_pmnc_write(u32 val)
  25 +{
  26 + val &= ARMV7_PMNC_MASK;
  27 + isb();
  28 + asm volatile("mcr p15, 0, %0, c9, c12, 0" :: "r"(val));
  29 +}
  30 +*/
  31 +
  32 +int init_module()
  33 +{
  34 + unsigned int regr;
  35 + unsigned int i;
  36 + unsigned int a, b;
  37 +
  38 + asm volatile("mrc p15, 0, %0, c9, c14, 0" : "=r" (regr));
  39 + pr_info("regr: %x\n", regr);
  40 +
  41 + regr = 0;
  42 + for (i = 0; i < 1000; i++) {
  43 + asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (a));
  44 + asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (b));
  45 + regr += b - a;
  46 + pr_info("overhead: %u\n", b - a);
  47 + }
  48 + pr_info("Measurement overhead: %u\n", regr);
  49 +
  50 +
  51 + return 1;
  52 +}
  53 +
  54 +void cleanup_module()
  55 +{
  56 +}
drivers/osproject_syscall.c View file @ fd96d80
  1 +#include <linux/module.h>
  2 +#include <linux/sched.h>
  3 +
  4 +int init_module()
  5 +{
  6 + unsigned int regr;
  7 + unsigned int i;
  8 + unsigned int a, b;
  9 +
  10 + asm volatile("mrc p15, 0, %0, c9, c14, 0" : "=r" (regr));
  11 + pr_info("User access regr: %x\n", regr);
  12 +
  13 + asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (a));
  14 + i = current->pid;
  15 + asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (b));
  16 +
  17 + pr_info("PID: %u, Time for getpid: %u\n", i, b - a);
  18 + return 0;
  19 +}
  20 +
  21 +void cleanup_module()
  22 +{
  23 +}
drivers/osproject_task.c View file @ fd96d80
  1 +#include <stdio.h>
  2 +
  3 +int main()
  4 +{
  5 + unsigned int regr;
  6 + unsigned int a, b;
  7 + unsigned int avg;
  8 + unsigned int pid;
  9 +
  10 + asm volatile("mrc p15, 0, %0, c9, c14, 0" : "=r" (regr));
  11 + printf("regr: %x\n", regr);
  12 +
  13 + for (regr = 0; regr < 100; regr++) {
  14 + asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (a));
  15 + asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (b));
  16 + regr += (b - a);
  17 + }
  18 +
  19 + regr /= 100;
  20 + printf("Measurement overhead: %u\n", regr);
  21 + regr = 0;
  22 + while (regr < 100) {
  23 + asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (a));
  24 + pid = fork();
  25 + asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (b));
  26 + printf("Time for fork: %u\n", b - a);
  27 + avg += (b - a);
  28 + regr++;
  29 + kill(pid, SIGKILL);
  30 + }
  31 +
  32 + printf("Fork avg: %u\n", avg/100);
  33 + return 1;
  34 +}