irqbalance.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. 'use strict';
  2. 'require view';
  3. 'require fs';
  4. 'require form';
  5. 'require ui';
  6. 'require rpc';
  7. const callServiceList = rpc.declare({
  8. object: 'service',
  9. method: 'list',
  10. params: ['name'],
  11. expect: { '': {} },
  12. });
  13. function getServiceStatus() {
  14. return L.resolveDefault(callServiceList('irqbalance'), {}).then(function (res) {
  15. try {
  16. return res['irqbalance']['instances']['irqbalance']['running'];
  17. } catch (e) {
  18. return false;
  19. }
  20. });
  21. }
  22. function renderStatus(isRunning) {
  23. const spanTemp = '<span style="color:%s"><strong>%s</strong></span>';
  24. return isRunning
  25. ? String.format(spanTemp, 'green', _('RUNNING'))
  26. : String.format(spanTemp, 'red', _('NOT RUNNING'));
  27. }
  28. return view.extend({
  29. load() {
  30. return L.resolveDefault(fs.read_direct('/proc/interrupts'));
  31. },
  32. render(data) {
  33. const cpuNum = data.match(/\bCPU\d+\b/g).map(i => i.slice(3)), // cpuNum = data.match(/(?<=\bCPU)\d+\b/g), // Safari did not support RegExp lookbehind assertion before version 16.4.
  34. irqNum = data.match(/\b\d+(?=: )/g);
  35. let m, s, o;
  36. m = new form.Map('irqbalance', _('irqbalance'), _('The purpose of irqbalance is to distribute hardware interrupts across processors/cores on a multiprocessor/multicore system in order to increase performance.'));
  37. s = m.section(form.NamedSection);
  38. s.anonymous = true;
  39. s.render = function () {
  40. L.Poll.add(function () {
  41. return L.resolveDefault(getServiceStatus()).then(function (res) {
  42. const view = document.getElementById('status');
  43. view.innerHTML = renderStatus(res);
  44. });
  45. });
  46. return E('div', { class: 'cbi-section' }, [
  47. E('p', { id: 'status' }, _('Loading...'))
  48. ]);
  49. }
  50. s = m.section(form.TypedSection, 'irqbalance', _('Snapshot of current IRQs'));
  51. s.anonymous = true;
  52. s = m.section(form.NamedSection);
  53. s.anonymous = true;
  54. s.render = function () {
  55. const snapshot = new ui.Textarea(data.slice(0, -1), {
  56. readonly: true,
  57. placeholder: _('Loading...'),
  58. monospace: true,
  59. rows: data.split('\n').length - 1,
  60. });
  61. return snapshot.render();
  62. }
  63. s = m.section(form.TypedSection, 'irqbalance', _('General settings'));
  64. s.anonymous = true;
  65. o = s.option(form.Flag, 'enabled', _('Enable'));
  66. o.default = '0';
  67. o.rmempty = false;
  68. o = s.option(form.Value, 'deepestcache', _('Deepest cache'), _('Cache level at which irqbalance partitions cache domains.'));
  69. o.placeholder = '2';
  70. o.datatype = 'uinteger';
  71. o.optional = true;
  72. o = s.option(form.Value, 'interval', _('Interval'), _('Value in seconds.'));
  73. o.placeholder = '10';
  74. o.datatype = 'uinteger';
  75. o.optional = true;
  76. o = s.option(form.Value, 'banned_cpulist', _('Exclude CPUs'), _('List of CPUs to ignore, can be an integer or integers separated by commas.') + '<br />' + _('Valid values: %s.').format(cpuNum.join(', ')));
  77. o.placeholder = '0';
  78. o.optional = true;
  79. o.validate = function (section_id, value) {
  80. for (const i of value.split(',')) {
  81. if (!cpuNum.includes(i) && i != '') {
  82. return _('Invalid');
  83. }
  84. }
  85. return true;
  86. }
  87. o = s.option(form.DynamicList, 'banirq', _('Exclude IRQs'), _('List of IRQs to ignore.') + '<br />' + _('Valid values: %s.').format(irqNum.join(', ')));
  88. o.placeholder = '36';
  89. o.datatype = 'uinteger';
  90. o.optional = true;
  91. o.validate = function (section_id, value) {
  92. return !irqNum.includes(value) && value != ''
  93. ? _('Invalid')
  94. : true;
  95. }
  96. o = s.option(form.Flag, 'debug', _('Show debug output'), _('Show debug output in system log.'));
  97. return m.render();
  98. }
  99. });