proximity.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* proximity.c
  2. * Parse manual proximity config.
  3. */
  4. #include <stdlib.h>
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <sys/types.h>
  8. #include <dirent.h>
  9. #include <limits.h>
  10. #include <ctype.h>
  11. #include "lub/list.h"
  12. #include "proximity.h"
  13. #define STR(str) ( str ? str : "" )
  14. int parse_pxm_config(const char *fname)
  15. {
  16. FILE *file;
  17. char *line = NULL;
  18. size_t size = 0;
  19. char *saveptr;
  20. if (!fname)
  21. return -1;
  22. file = fopen(fname, "r");
  23. if (!file)
  24. return -1;
  25. while (!feof(file)) {
  26. if (getline(&line, &size, file) == 0)
  27. break;
  28. printf("%s\n", line);
  29. /* if (!strstr(line, "cpu"))
  30. break;
  31. cpunr = strtoul(&line[3], NULL, 10);
  32. cpu = cpu_list_search(cpus, cpunr);
  33. if (!cpu)
  34. continue;
  35. rc = sscanf(line, "%*s %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu",
  36. &l_user, &l_nice, &l_system, &l_idle, &l_iowait,
  37. &l_irq, &l_softirq, &l_steal, &l_guest, &l_guest_nice);
  38. if (rc < 2)
  39. break;
  40. cpucount++;
  41. load_all = l_user + l_nice + l_system + l_idle + l_iowait +
  42. l_irq + l_softirq + l_steal + l_guest + l_guest_nice;
  43. load_irq = l_irq + l_softirq;
  44. cpu->old_load = cpu->load;
  45. if (cpu->old_load_all == 0) {
  46. cpu->load = 0;
  47. } else {
  48. float d_all = (float)(load_all - cpu->old_load_all);
  49. float d_irq = (float)(load_irq - cpu->old_load_irq);
  50. cpu->load = d_irq * 100 / d_all;
  51. }
  52. cpu->old_load_all = load_all;
  53. cpu->old_load_irq = load_irq;
  54. */
  55. }
  56. /* Parse "intr" line. Get number of interrupts. */
  57. #if 0
  58. strtok_r(line, " ", &saveptr);
  59. strtok_r(NULL, " ", &saveptr); /* Total number of interrupts */
  60. for (intr_str = strtok_r(NULL, " ", &saveptr);
  61. intr_str; intr_str = strtok_r(NULL, " ", &saveptr)) {
  62. unsigned long long intr = 0;
  63. char *endptr;
  64. irq_t *irq;
  65. irq = irq_list_search(irqs, inum);
  66. inum++;
  67. if (!irq)
  68. continue;
  69. intr = strtoull(intr_str, &endptr, 10);
  70. if (endptr == intr_str)
  71. intr = 0;
  72. if (irq->old_intr == 0)
  73. irq->intr = 0;
  74. else
  75. irq->intr = intr - irq->old_intr;
  76. irq->old_intr = intr;
  77. }
  78. #endif
  79. fclose(file);
  80. free(line);
  81. return 0;
  82. }