]> git.alsa-project.org Git - alsa-lib.git/commitdiff
test: latency - add --policy option to allow using SCHED_FIFO
authorJaroslav Kysela <perex@perex.cz>
Thu, 24 Nov 2022 07:33:47 +0000 (08:33 +0100)
committerJaroslav Kysela <perex@perex.cz>
Thu, 24 Nov 2022 07:33:47 +0000 (08:33 +0100)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
test/latency.c

index 1b4848d64e144d569580f15fcac3e8684468d5a2..3b20e1c10f49f1b31a1da71fa4dc2c0706566887 100644 (file)
@@ -40,6 +40,7 @@
 
 typedef struct timespec timestamp_t;
 
+char *sched_policy = "rr";
 char *pdevice = "hw:0,0";
 char *cdevice = "hw:0,0";
 snd_pcm_format_t format = SND_PCM_FORMAT_S16_LE;
@@ -354,18 +355,24 @@ void gettimestamp(snd_pcm_t *handle, snd_timestamp_t *timestamp)
 void setscheduler(void)
 {
        struct sched_param sched_param;
+       int policy = SCHED_RR;
+       const char *spolicy = "Round Robin";
 
+       if (strcasecmp(sched_policy, "fifo") == 0) {
+               policy = SCHED_FIFO;
+               spolicy = "FIFO";
+       }
        if (sched_getparam(0, &sched_param) < 0) {
                printf("Scheduler getparam failed...\n");
                return;
        }
-       sched_param.sched_priority = sched_get_priority_max(SCHED_RR);
-       if (!sched_setscheduler(0, SCHED_RR, &sched_param)) {
-               printf("Scheduler set to Round Robin with priority %i...\n", sched_param.sched_priority);
+       sched_param.sched_priority = sched_get_priority_max(policy);
+       if (!sched_setscheduler(0, policy, &sched_param)) {
+               printf("Scheduler set to %s with priority %i...\n", spolicy, sched_param.sched_priority);
                fflush(stdout);
                return;
        }
-       printf("!!!Scheduler set to Round Robin with priority %i FAILED!!!\n", sched_param.sched_priority);
+       printf("!!!Scheduler set to %s with priority %i FAILED!!!\n", spolicy, sched_param.sched_priority);
 }
 
 long timediff(snd_timestamp_t t1, snd_timestamp_t t2)
@@ -515,6 +522,7 @@ void help(void)
 "-e,--effect    apply an effect (bandpass filter sweep)\n"
 "-x,--posdump   dump buffer positions\n"
 "-X,--realtime  do a realtime check (buffering)\n"
+"-O,--policy    set scheduler policy (RR or FIFO)\n"
 );
         printf("Recognized sample formats are:");
         for (k = 0; k < SND_PCM_FORMAT_LAST; ++k) {
@@ -555,6 +563,7 @@ int main(int argc, char *argv[])
                {"effect", 0, NULL, 'e'},
                {"posdump", 0, NULL, 'x'},
                {"realtime", 0, NULL, 'X'},
+               {"policy", 1, NULL, 'O'},
                {NULL, 0, NULL, 0},
        };
        snd_pcm_t *phandle, *chandle;
@@ -569,7 +578,7 @@ int main(int argc, char *argv[])
        morehelp = 0;
        while (1) {
                int c;
-               if ((c = getopt_long(argc, argv, "hP:C:m:M:U:F:f:c:r:B:E:s:y:bpenxX", long_option, NULL)) < 0)
+               if ((c = getopt_long(argc, argv, "hP:C:m:M:U:F:f:c:r:B:E:s:y:O:bpenxX", long_option, NULL)) < 0)
                        break;
                switch (c) {
                case 'h':
@@ -643,6 +652,9 @@ int main(int argc, char *argv[])
                case 'X':
                        realtime_check = 1;
                        break;
+               case 'O':
+                       sched_policy = optarg;
+                       break;
                }
        }