dscr_sysfs_thread_test.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * POWER Data Stream Control Register (DSCR) sysfs thread test
  3. *
  4. * This test updates the system wide DSCR default value through
  5. * sysfs interface which should then update all the CPU specific
  6. * DSCR default values which must also be then visible to threads
  7. * executing on individual CPUs on the system.
  8. *
  9. * Copyright 2015, Anshuman Khandual, IBM Corporation.
  10. *
  11. * This program is free software; you can redistribute it and/or modify it
  12. * under the terms of the GNU General Public License version 2 as published
  13. * by the Free Software Foundation.
  14. */
  15. #define _GNU_SOURCE
  16. #include "dscr.h"
  17. static int test_thread_dscr(unsigned long val)
  18. {
  19. unsigned long cur_dscr, cur_dscr_usr;
  20. cur_dscr = get_dscr();
  21. cur_dscr_usr = get_dscr_usr();
  22. if (val != cur_dscr) {
  23. printf("[cpu %d] Kernel DSCR should be %ld but is %ld\n",
  24. sched_getcpu(), val, cur_dscr);
  25. return 1;
  26. }
  27. if (val != cur_dscr_usr) {
  28. printf("[cpu %d] User DSCR should be %ld but is %ld\n",
  29. sched_getcpu(), val, cur_dscr_usr);
  30. return 1;
  31. }
  32. return 0;
  33. }
  34. static int check_cpu_dscr_thread(unsigned long val)
  35. {
  36. cpu_set_t mask;
  37. int cpu;
  38. for (cpu = 0; cpu < CPU_SETSIZE; cpu++) {
  39. CPU_ZERO(&mask);
  40. CPU_SET(cpu, &mask);
  41. if (sched_setaffinity(0, sizeof(mask), &mask))
  42. continue;
  43. if (test_thread_dscr(val))
  44. return 1;
  45. }
  46. return 0;
  47. }
  48. int dscr_sysfs_thread(void)
  49. {
  50. unsigned long orig_dscr_default;
  51. int i, j;
  52. orig_dscr_default = get_default_dscr();
  53. for (i = 0; i < COUNT; i++) {
  54. for (j = 0; j < DSCR_MAX; j++) {
  55. set_default_dscr(j);
  56. if (check_cpu_dscr_thread(j))
  57. goto fail;
  58. }
  59. }
  60. set_default_dscr(orig_dscr_default);
  61. return 0;
  62. fail:
  63. set_default_dscr(orig_dscr_default);
  64. return 1;
  65. }
  66. int main(int argc, char *argv[])
  67. {
  68. return test_harness(dscr_sysfs_thread, "dscr_sysfs_thread_test");
  69. }