From 8e4bff4cab0ddac6060645b0715210484d02ff40 Mon Sep 17 00:00:00 2001 From: Yuval Adam <_@yuv.al> Date: Wed, 30 Aug 2017 08:25:59 +0000 Subject: Initial file dump from open source release --- drivers/misc/bootperf/Kconfig | 5 + drivers/misc/bootperf/Makefile | 1 + drivers/misc/bootperf/bootperf.c | 268 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 274 insertions(+) create mode 100644 drivers/misc/bootperf/Kconfig create mode 100644 drivers/misc/bootperf/Makefile create mode 100644 drivers/misc/bootperf/bootperf.c (limited to 'drivers/misc/bootperf') diff --git a/drivers/misc/bootperf/Kconfig b/drivers/misc/bootperf/Kconfig new file mode 100644 index 00000000..29185591 --- /dev/null +++ b/drivers/misc/bootperf/Kconfig @@ -0,0 +1,5 @@ +config BOOT_PERF + bool "enable boot time reord and read" + default n + help + enable boot time reord and read diff --git a/drivers/misc/bootperf/Makefile b/drivers/misc/bootperf/Makefile new file mode 100644 index 00000000..e7179edf --- /dev/null +++ b/drivers/misc/bootperf/Makefile @@ -0,0 +1 @@ +obj-$(CONFIG_BOOT_PERF) += bootperf.o diff --git a/drivers/misc/bootperf/bootperf.c b/drivers/misc/bootperf/bootperf.c new file mode 100644 index 00000000..f72b7cea --- /dev/null +++ b/drivers/misc/bootperf/bootperf.c @@ -0,0 +1,268 @@ +#include +#include +#include +#include +#include +#include + +#define BOOT_STR_SIZE 512 +#define BOOT_LOG_NUM 128 + +struct boot_log_struct{ + u64 timestamp; + char event[BOOT_STR_SIZE]; + bool isdelta; +}sprd_bootperf[BOOT_LOG_NUM]; +int boot_log_count = 0; + +//static DEFINE_MUTEX(sprd_bootperf_lock); +static int sprd_bootperf_enabled = 1; +static int pl_t = 0; +static int lcd_t = 0; +static int loadimg_t = 0; +/* + * Ease the printing of nsec fields: + */ +/* +static long long nsec_high(unsigned long long nsec) +{ + if ((long long)nsec < 0) { + nsec = -nsec; + do_div(nsec, 1000000); + return -nsec; + } + do_div(nsec, 1000000); + + return nsec; +} + +static unsigned long nsec_low(unsigned long long nsec) +{ + if ((long long)nsec < 0) + nsec = -nsec; + + return do_div(nsec, 1000000); +} +#define SPLIT_NS(x) nsec_high(x), nsec_low(x) +*/ +void log_boot(char *str, unsigned long long duration) +{ + if( 0 == sprd_bootperf_enabled) + return; + + if(boot_log_count >= BOOT_LOG_NUM) + { + printk("[BOOTPERF] not enuough bootperf buffer\n"); + return; + } + // mutex_lock(&sprd_bootperf_lock); + if(duration>0) + { + sprd_bootperf[boot_log_count].timestamp = duration; + sprd_bootperf[boot_log_count].isdelta=true; + } + + strcpy((char*)&sprd_bootperf[boot_log_count].event, str); + boot_log_count++; + // mutex_unlock(&sprd_bootperf_lock); +} + + +//extern void (*set_intact_mode)(void); +static void sprd_bootperf_switch(int on) +{ + // mutex_lock(&sprd_bootperf_lock); + if (sprd_bootperf_enabled ^ on) + { + if (on) + { + sprd_bootperf_enabled = 1; + } + else + { + sprd_bootperf_enabled = 0; + } + } + // mutex_unlock(&sprd_bootperf_lock); + +} + +static ssize_t sprd_bootperf_write(struct file *filp, const char *ubuf, + size_t cnt, loff_t *data) +{ + char buf[BOOT_STR_SIZE]; + size_t copy_size = cnt; + + if (cnt >= sizeof(buf)) + copy_size = BOOT_STR_SIZE - 1; + + if (copy_from_user(&buf, ubuf, copy_size)) + return -EFAULT; + + if(cnt==1){ + if(buf[0] == '0') + sprd_bootperf_switch(0); + else if(buf[0] == '1') + sprd_bootperf_switch(1); + } + + buf[copy_size] = 0; + log_boot(buf,0); + + return cnt; + +} + +static ssize_t sprd_bootperf_read(struct file *file, char __user *ubuf, + size_t count, loff_t *ppos) +{ + int i=0; + int len =0; + int total_len=0; + char buf[256]={0}; + if( 0 == sprd_bootperf_enabled) + return -EFAULT; + if ((file->f_flags & O_NONBLOCK) && + (boot_log_count == 0) &&(pl_t<=0)) + return -EAGAIN; + if(lcd_t > 0) + { + len=sprintf(buf,"event:%s, takes: %d ms\n", "initlcd", lcd_t); + if(len < count) + { + if(copy_to_user(ubuf, buf, len)) + { + return -EFAULT; + } + total_len+=len; + ubuf+=len; + } + else + { + printk("user buffer is not enough, count %d, len %d\n",count,len); + return -EFAULT; + } + } + if(loadimg_t > 0) + { + len=sprintf(buf,"event:%s, takes: %d ms\n", "loadimage", loadimg_t); + if(len < count) + { + if(copy_to_user(ubuf, buf, len)) + { + return -EFAULT; + } + total_len+=len; + ubuf+=len; + } + else + { + printk("user buffer is not enough, count %d, len %d\n",count,len); + return -EFAULT; + } + } + if(pl_t > 0) + { + len=sprintf(buf,"event:%s, takes: %d ms\n", "bootload", pl_t); + if(len < count) + { + if(copy_to_user(ubuf, buf, len)) + { + return -EFAULT; + } + total_len+=len; + ubuf+=len; + } + else + { + printk("user buffer is not enough, count %d, len %d\n",count,len); + return -EFAULT; + } + } + for (i=0;i