b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | #include <linux/debugfs.h>
|
| 2 | #include <linux/uaccess.h>
|
| 3 | #include <linux/module.h>
|
| 4 | #include <linux/io.h>
|
| 5 | #include <linux/cpufreq.h>
|
| 6 |
|
| 7 |
|
| 8 | #define CPU_MIPS_LOOP 250000000
|
| 9 | static unsigned int get_cpu_mips(void)
|
| 10 | {
|
| 11 | struct timespec64 v1, v2;
|
| 12 | unsigned long cnt, total;
|
| 13 | #ifdef CONFIG_ARM64
|
| 14 | unsigned long i;
|
| 15 | #endif
|
| 16 |
|
| 17 | cnt = CPU_MIPS_LOOP;
|
| 18 | raw_local_irq_disable();
|
| 19 | ktime_get_real_ts64(&v1);
|
| 20 | #ifdef CONFIG_ARM64
|
| 21 | __asm__ __volatile__(
|
| 22 | "mov %0, %1\n"
|
| 23 | "timer_loop: subs %0, %0, #1\n"
|
| 24 | "bhi timer_loop"
|
| 25 | : "=&r" (i)
|
| 26 | : "r" (cnt)
|
| 27 | : "cc");
|
| 28 | #else
|
| 29 | while (cnt--)
|
| 30 | barrier();
|
| 31 | #endif
|
| 32 | ktime_get_real_ts64(&v2);
|
| 33 | raw_local_irq_enable();
|
| 34 | total = (v2.tv_sec - v1.tv_sec) * 1000000 + (v2.tv_nsec - v1.tv_nsec) / 1000;
|
| 35 |
|
| 36 | return CPU_MIPS_LOOP / total;
|
| 37 | }
|
| 38 |
|
| 39 | static ssize_t mips_read(struct file *filp, char __user *buffer,
|
| 40 | size_t count, loff_t *ppos)
|
| 41 | {
|
| 42 | unsigned int mips, cpu;
|
| 43 |
|
| 44 | mips = get_cpu_mips();
|
| 45 | cpu = raw_smp_processor_id();
|
| 46 | pr_info("Attention! You need to keep cpufreq don't change!\n");
|
| 47 | pr_info("Calculated out MIPS is %dMhz, while setting is %dkhz\n",
|
| 48 | mips, cpufreq_get(cpu));
|
| 49 | return 0;
|
| 50 | }
|
| 51 |
|
| 52 | const struct file_operations show_mips_fops = {
|
| 53 | .read = mips_read,
|
| 54 | };
|
| 55 |
|
| 56 | struct dentry *asr_debug_entry;
|
| 57 |
|
| 58 | static int __init asr_debugfs_init(void)
|
| 59 | {
|
| 60 | struct dentry *showmips;
|
| 61 |
|
| 62 | asr_debug_entry = debugfs_create_dir("asr", NULL);
|
| 63 | if (!asr_debug_entry)
|
| 64 | return -ENOENT;
|
| 65 |
|
| 66 | showmips = debugfs_create_file("showmips", 0664,
|
| 67 | asr_debug_entry, NULL, &show_mips_fops);
|
| 68 | if (!showmips)
|
| 69 | goto err_mips;
|
| 70 |
|
| 71 | return 0;
|
| 72 |
|
| 73 | err_mips:
|
| 74 | debugfs_remove(asr_debug_entry);
|
| 75 | asr_debug_entry = NULL;
|
| 76 | return -ENOENT;
|
| 77 | }
|
| 78 |
|
| 79 | core_initcall_sync(asr_debugfs_init); |