Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * POWER Data Stream Control Register (DSCR) sysfs interface test
0004  *
0005  * This test updates to system wide DSCR default through the sysfs interface
0006  * and then verifies that all the CPU specific DSCR defaults are updated as
0007  * well verified from their sysfs interfaces.
0008  *
0009  * Copyright 2015, Anshuman Khandual, IBM Corporation.
0010  */
0011 #include "dscr.h"
0012 
0013 static int check_cpu_dscr_default(char *file, unsigned long val)
0014 {
0015     char buf[10];
0016     int fd, rc;
0017 
0018     fd = open(file, O_RDWR);
0019     if (fd == -1) {
0020         perror("open() failed");
0021         return 1;
0022     }
0023 
0024     rc = read(fd, buf, sizeof(buf));
0025     if (rc == -1) {
0026         perror("read() failed");
0027         return 1;
0028     }
0029     close(fd);
0030 
0031     buf[rc] = '\0';
0032     if (strtol(buf, NULL, 16) != val) {
0033         printf("DSCR match failed: %ld (system) %ld (cpu)\n",
0034                     val, strtol(buf, NULL, 16));
0035         return 1;
0036     }
0037     return 0;
0038 }
0039 
0040 static int check_all_cpu_dscr_defaults(unsigned long val)
0041 {
0042     DIR *sysfs;
0043     struct dirent *dp;
0044     char file[LEN_MAX];
0045 
0046     sysfs = opendir(CPU_PATH);
0047     if (!sysfs) {
0048         perror("opendir() failed");
0049         return 1;
0050     }
0051 
0052     while ((dp = readdir(sysfs))) {
0053         int len;
0054 
0055         if (!(dp->d_type & DT_DIR))
0056             continue;
0057         if (!strcmp(dp->d_name, "cpuidle"))
0058             continue;
0059         if (!strstr(dp->d_name, "cpu"))
0060             continue;
0061 
0062         len = snprintf(file, LEN_MAX, "%s%s/dscr", CPU_PATH, dp->d_name);
0063         if (len >= LEN_MAX)
0064             continue;
0065         if (access(file, F_OK))
0066             continue;
0067 
0068         if (check_cpu_dscr_default(file, val))
0069             return 1;
0070     }
0071     closedir(sysfs);
0072     return 0;
0073 }
0074 
0075 int dscr_sysfs(void)
0076 {
0077     unsigned long orig_dscr_default;
0078     int i, j;
0079 
0080     SKIP_IF(!have_hwcap2(PPC_FEATURE2_DSCR));
0081 
0082     orig_dscr_default = get_default_dscr();
0083     for (i = 0; i < COUNT; i++) {
0084         for (j = 0; j < DSCR_MAX; j++) {
0085             set_default_dscr(j);
0086             if (check_all_cpu_dscr_defaults(j))
0087                 goto fail;
0088         }
0089     }
0090     set_default_dscr(orig_dscr_default);
0091     return 0;
0092 fail:
0093     set_default_dscr(orig_dscr_default);
0094     return 1;
0095 }
0096 
0097 int main(int argc, char *argv[])
0098 {
0099     return test_harness(dscr_sysfs, "dscr_sysfs_test");
0100 }