2 * POWER Data Stream Control Register (DSCR) sysfs interface test
4 * This test updates to system wide DSCR default through the sysfs interface
5 * and then verifies that all the CPU specific DSCR defaults are updated as
6 * well verified from their sysfs interfaces.
8 * Copyright 2015, Anshuman Khandual, IBM Corporation.
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published
12 * by the Free Software Foundation.
16 static int check_cpu_dscr_default(char *file, unsigned long val)
21 fd = open(file, O_RDWR);
23 perror("open() failed");
27 rc = read(fd, buf, sizeof(buf));
29 perror("read() failed");
35 if (strtol(buf, NULL, 16) != val) {
36 printf("DSCR match failed: %ld (system) %ld (cpu)\n",
37 val, strtol(buf, NULL, 16));
43 static int check_all_cpu_dscr_defaults(unsigned long val)
49 sysfs = opendir(CPU_PATH);
51 perror("opendir() failed");
55 while ((dp = readdir(sysfs))) {
56 if (!(dp->d_type & DT_DIR))
58 if (!strcmp(dp->d_name, "cpuidle"))
60 if (!strstr(dp->d_name, "cpu"))
63 sprintf(file, "%s%s/dscr", CPU_PATH, dp->d_name);
64 if (access(file, F_OK))
67 if (check_cpu_dscr_default(file, val))
76 unsigned long orig_dscr_default;
79 orig_dscr_default = get_default_dscr();
80 for (i = 0; i < COUNT; i++) {
81 for (j = 0; j < DSCR_MAX; j++) {
83 if (check_all_cpu_dscr_defaults(j))
87 set_default_dscr(orig_dscr_default);
90 set_default_dscr(orig_dscr_default);
94 int main(int argc, char *argv[])
96 return test_harness(dscr_sysfs, "dscr_sysfs_test");