| | 1039 | // |
|---|
| | 1040 | // |
|---|
| | 1041 | bool interrupts_idle(time_t t) { |
|---|
| | 1042 | static FILE *ifp = NULL; |
|---|
| | 1043 | static long irq_count[256]; |
|---|
| | 1044 | static time_t last_irq = time(NULL); |
|---|
| | 1045 | |
|---|
| | 1046 | char line[256]; |
|---|
| | 1047 | int i = 0; |
|---|
| | 1048 | long ccount = 0; |
|---|
| | 1049 | |
|---|
| | 1050 | if (ifp == NULL) { |
|---|
| | 1051 | if ((ifp = fopen("/proc/interrupts", "r")) == NULL) { |
|---|
| | 1052 | return true; |
|---|
| | 1053 | } |
|---|
| | 1054 | } |
|---|
| | 1055 | rewind(ifp); |
|---|
| | 1056 | while (fgets(line, sizeof(line), ifp)) { |
|---|
| | 1057 | // Check for mouse, keyboard and PS/2 devices. |
|---|
| | 1058 | if (strcasestr(line, "mouse") != NULL || |
|---|
| | 1059 | strcasestr(line, "keyboard") != NULL || |
|---|
| | 1060 | strcasestr(line, "i8042") != NULL) { |
|---|
| | 1061 | // If any IRQ count changed, update last_irq. |
|---|
| | 1062 | if (sscanf(line, "%d: %ld", &i, &ccount) == 2 && |
|---|
| | 1063 | irq_count[i] != ccount) { |
|---|
| | 1064 | last_irq = time(NULL); |
|---|
| | 1065 | irq_count[i] = ccount; |
|---|
| | 1066 | } |
|---|
| | 1067 | } |
|---|
| | 1068 | } |
|---|
| | 1069 | return last_irq < t; |
|---|
| | 1070 | } |
|---|
| | 1071 | |
|---|