Skip to content

Commit 270b2a6

Browse files
Frederic WeisbeckerKAGA-KOKO
authored andcommitted
selftests/proc: Remove idle time monotonicity assertions
Due to broken iowait task counting design (cf: comments above get_cpu_idle_time_us() and nr_iowait()), it is not possible to provide the guarantee that /proc/stat or /proc/uptime display monotonic idle time values. Remove the assertions that verify the related wrong assumption so that testers and maintainers don't spend more time on that. Reported-by: Yu Liao <liaoyu15@huawei.com> Reported-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Frederic Weisbecker <frederic@kernel.org> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Link: https://lore.kernel.org/r/20230222144649.624380-8-frederic@kernel.org
1 parent 9a1d4b8 commit 270b2a6

3 files changed

Lines changed: 14 additions & 27 deletions

File tree

tools/testing/selftests/proc/proc-uptime-001.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1414
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1515
*/
16-
// Test that values in /proc/uptime increment monotonically.
16+
// Test that boottime value in /proc/uptime increments monotonically.
17+
// We don't test idle time monotonicity due to broken iowait task
18+
// counting, cf: comment above get_cpu_idle_time_us()
1719
#undef NDEBUG
1820
#include <assert.h>
1921
#include <stdint.h>
@@ -25,20 +27,18 @@
2527

2628
int main(void)
2729
{
28-
uint64_t start, u0, u1, i0, i1;
30+
uint64_t start, u0, u1;
2931
int fd;
3032

3133
fd = open("/proc/uptime", O_RDONLY);
3234
assert(fd >= 0);
3335

34-
proc_uptime(fd, &u0, &i0);
36+
u0 = proc_uptime(fd);
3537
start = u0;
3638
do {
37-
proc_uptime(fd, &u1, &i1);
39+
u1 = proc_uptime(fd);
3840
assert(u1 >= u0);
39-
assert(i1 >= i0);
4041
u0 = u1;
41-
i0 = i1;
4242
} while (u1 - start < 100);
4343

4444
return 0;

tools/testing/selftests/proc/proc-uptime-002.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1414
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1515
*/
16-
// Test that values in /proc/uptime increment monotonically
17-
// while shifting across CPUs.
16+
// Test that boottime value in /proc/uptime increments monotonically
17+
// while shifting across CPUs. We don't test idle time monotonicity
18+
// due to broken iowait task counting, cf: comment above get_cpu_idle_time_us()
1819
#undef NDEBUG
1920
#include <assert.h>
2021
#include <errno.h>
@@ -45,7 +46,7 @@ int main(void)
4546
unsigned int len;
4647
unsigned long *m;
4748
unsigned int cpu;
48-
uint64_t u0, u1, i0, i1;
49+
uint64_t u0, u1;
4950
int fd;
5051

5152
/* find out "nr_cpu_ids" */
@@ -60,19 +61,17 @@ int main(void)
6061
fd = open("/proc/uptime", O_RDONLY);
6162
assert(fd >= 0);
6263

63-
proc_uptime(fd, &u0, &i0);
64+
u0 = proc_uptime(fd);
6465
for (cpu = 0; cpu < len * 8; cpu++) {
6566
memset(m, 0, len);
6667
m[cpu / (8 * sizeof(unsigned long))] |= 1UL << (cpu % (8 * sizeof(unsigned long)));
6768

6869
/* CPU might not exist, ignore error */
6970
sys_sched_setaffinity(0, len, m);
7071

71-
proc_uptime(fd, &u1, &i1);
72+
u1 = proc_uptime(fd);
7273
assert(u1 >= u0);
73-
assert(i1 >= i0);
7474
u0 = u1;
75-
i0 = i1;
7675
}
7776

7877
return 0;

tools/testing/selftests/proc/proc-uptime.h

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
#include "proc.h"
2424

25-
static void proc_uptime(int fd, uint64_t *uptime, uint64_t *idle)
25+
static uint64_t proc_uptime(int fd)
2626
{
2727
uint64_t val1, val2;
2828
char buf[64], *p;
@@ -43,18 +43,6 @@ static void proc_uptime(int fd, uint64_t *uptime, uint64_t *idle)
4343
assert(p[3] == ' ');
4444

4545
val2 = (p[1] - '0') * 10 + p[2] - '0';
46-
*uptime = val1 * 100 + val2;
4746

48-
p += 4;
49-
50-
val1 = xstrtoull(p, &p);
51-
assert(p[0] == '.');
52-
assert('0' <= p[1] && p[1] <= '9');
53-
assert('0' <= p[2] && p[2] <= '9');
54-
assert(p[3] == '\n');
55-
56-
val2 = (p[1] - '0') * 10 + p[2] - '0';
57-
*idle = val1 * 100 + val2;
58-
59-
assert(p + 4 == buf + rv);
47+
return val1 * 100 + val2;
6048
}

0 commit comments

Comments
 (0)