dhry_run.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Dhrystone benchmark test module
  4. *
  5. * Copyright (C) 2022 Glider bv
  6. */
  7. #include "dhry.h"
  8. #include <linux/kernel.h>
  9. #include <linux/module.h>
  10. #include <linux/moduleparam.h>
  11. #include <linux/smp.h>
  12. #define DHRY_VAX 1757
  13. static int dhry_run_set(const char *val, const struct kernel_param *kp);
  14. static const struct kernel_param_ops run_ops = {
  15. .flags = KERNEL_PARAM_OPS_FL_NOARG,
  16. .set = dhry_run_set,
  17. };
  18. static bool dhry_run;
  19. module_param_cb(run, &run_ops, &dhry_run, 0200);
  20. MODULE_PARM_DESC(run, "Run the test (default: false)");
  21. static int iterations = -1;
  22. module_param(iterations, int, 0644);
  23. MODULE_PARM_DESC(iterations,
  24. "Number of iterations through the benchmark (default: auto)");
  25. static void dhry_benchmark(void)
  26. {
  27. unsigned int cpu = get_cpu();
  28. int i, n;
  29. if (iterations > 0) {
  30. n = dhry(iterations);
  31. goto report;
  32. }
  33. for (i = DHRY_VAX; i > 0; i <<= 1) {
  34. n = dhry(i);
  35. if (n != -EAGAIN)
  36. break;
  37. }
  38. report:
  39. put_cpu();
  40. if (n >= 0)
  41. pr_info("CPU%u: Dhrystones per Second: %d (%d DMIPS)\n", cpu,
  42. n, n / DHRY_VAX);
  43. else if (n == -EAGAIN)
  44. pr_err("Please increase the number of iterations\n");
  45. else
  46. pr_err("Dhrystone benchmark failed error %pe\n", ERR_PTR(n));
  47. }
  48. static int dhry_run_set(const char *val, const struct kernel_param *kp)
  49. {
  50. int ret;
  51. if (val) {
  52. ret = param_set_bool(val, kp);
  53. if (ret)
  54. return ret;
  55. } else {
  56. dhry_run = true;
  57. }
  58. if (dhry_run && system_state == SYSTEM_RUNNING)
  59. dhry_benchmark();
  60. return 0;
  61. }
  62. static int __init dhry_init(void)
  63. {
  64. if (dhry_run)
  65. dhry_benchmark();
  66. return 0;
  67. }
  68. module_init(dhry_init);
  69. MODULE_AUTHOR("Geert Uytterhoeven <geert+renesas@glider.be>");
  70. MODULE_DESCRIPTION("Dhrystone benchmark test module");
  71. MODULE_LICENSE("GPL");