~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/alsa/global-timer.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /tools/testing/selftests/alsa/global-timer.c (Architecture sparc) and /tools/testing/selftests/alsa/global-timer.c (Architecture sparc64)


  1 // SPDX-License-Identifier: GPL-2.0                 1 // SPDX-License-Identifier: GPL-2.0
  2 /*                                                  2 /*
  3  * This tool is used by the utimer test, and i      3  * This tool is used by the utimer test, and it allows us to
  4  * count the ticks of a global timer in a cert      4  * count the ticks of a global timer in a certain time frame
  5  * (which is set by `timeout` parameter).           5  * (which is set by `timeout` parameter).
  6  *                                                  6  *
  7  * Author: Ivan Orlov <ivan.orlov0322@gmail.co      7  * Author: Ivan Orlov <ivan.orlov0322@gmail.com>
  8  */                                                 8  */
  9 #include <stdio.h>                                  9 #include <stdio.h>
 10 #include <stdlib.h>                                10 #include <stdlib.h>
 11 #include <alsa/asoundlib.h>                        11 #include <alsa/asoundlib.h>
 12 #include <time.h>                                  12 #include <time.h>
 13                                                    13 
 14 static int ticked;                                 14 static int ticked;
 15 static void async_callback(snd_async_handler_t     15 static void async_callback(snd_async_handler_t *ahandler)
 16 {                                                  16 {
 17         ticked++;                                  17         ticked++;
 18 }                                                  18 }
 19                                                    19 
 20 static char timer_name[64];                        20 static char timer_name[64];
 21 static void bind_to_timer(int device, int subd     21 static void bind_to_timer(int device, int subdevice, int timeout)
 22 {                                                  22 {
 23         snd_timer_t *handle;                       23         snd_timer_t *handle;
 24         snd_timer_params_t *params;                24         snd_timer_params_t *params;
 25         snd_async_handler_t *ahandler;             25         snd_async_handler_t *ahandler;
 26                                                    26 
 27         time_t end;                                27         time_t end;
 28                                                    28 
 29         sprintf(timer_name, "hw:CLASS=%d,SCLAS     29         sprintf(timer_name, "hw:CLASS=%d,SCLASS=%d,DEV=%d,SUBDEV=%d",
 30                 SND_TIMER_CLASS_GLOBAL, SND_TI     30                 SND_TIMER_CLASS_GLOBAL, SND_TIMER_SCLASS_NONE,
 31                 device, subdevice);                31                 device, subdevice);
 32                                                    32 
 33         snd_timer_params_alloca(&params);          33         snd_timer_params_alloca(&params);
 34                                                    34 
 35         if (snd_timer_open(&handle, timer_name     35         if (snd_timer_open(&handle, timer_name, SND_TIMER_OPEN_NONBLOCK) < 0) {
 36                 perror("Can't open the timer")     36                 perror("Can't open the timer");
 37                 exit(EXIT_FAILURE);                37                 exit(EXIT_FAILURE);
 38         }                                          38         }
 39                                                    39 
 40         snd_timer_params_set_auto_start(params     40         snd_timer_params_set_auto_start(params, 1);
 41         snd_timer_params_set_ticks(params, 1);     41         snd_timer_params_set_ticks(params, 1);
 42         if (snd_timer_params(handle, params) <     42         if (snd_timer_params(handle, params) < 0) {
 43                 perror("Can't set timer params     43                 perror("Can't set timer params");
 44                 exit(EXIT_FAILURE);                44                 exit(EXIT_FAILURE);
 45         }                                          45         }
 46                                                    46 
 47         if (snd_async_add_timer_handler(&ahand     47         if (snd_async_add_timer_handler(&ahandler, handle, async_callback, NULL) < 0) {
 48                 perror("Can't create a handler     48                 perror("Can't create a handler");
 49                 exit(EXIT_FAILURE);                49                 exit(EXIT_FAILURE);
 50         }                                          50         }
 51         end = time(NULL) + timeout;                51         end = time(NULL) + timeout;
 52         if (snd_timer_start(handle) < 0) {         52         if (snd_timer_start(handle) < 0) {
 53                 perror("Failed to start the ti     53                 perror("Failed to start the timer");
 54                 exit(EXIT_FAILURE);                54                 exit(EXIT_FAILURE);
 55         }                                          55         }
 56         printf("Timer has started\n");             56         printf("Timer has started\n");
 57         while (time(NULL) <= end) {                57         while (time(NULL) <= end) {
 58                 /*                                 58                 /*
 59                  * Waiting for the timeout to      59                  * Waiting for the timeout to elapse. Can't use sleep here, as it gets
 60                  * constantly interrupted by t     60                  * constantly interrupted by the signal from the timer (SIGIO)
 61                  */                                61                  */
 62         }                                          62         }
 63         snd_timer_stop(handle);                    63         snd_timer_stop(handle);
 64         snd_timer_close(handle);                   64         snd_timer_close(handle);
 65 }                                                  65 }
 66                                                    66 
 67 int main(int argc, char *argv[])                   67 int main(int argc, char *argv[])
 68 {                                                  68 {
 69         int device, subdevice, timeout;            69         int device, subdevice, timeout;
 70                                                    70 
 71         if (argc < 4) {                            71         if (argc < 4) {
 72                 perror("Usage: %s <device> <su     72                 perror("Usage: %s <device> <subdevice> <timeout>");
 73                 return EXIT_FAILURE;               73                 return EXIT_FAILURE;
 74         }                                          74         }
 75                                                    75 
 76         setlinebuf(stdout);                        76         setlinebuf(stdout);
 77                                                    77 
 78         device = atoi(argv[1]);                    78         device = atoi(argv[1]);
 79         subdevice = atoi(argv[2]);                 79         subdevice = atoi(argv[2]);
 80         timeout = atoi(argv[3]);                   80         timeout = atoi(argv[3]);
 81                                                    81 
 82         bind_to_timer(device, subdevice, timeo     82         bind_to_timer(device, subdevice, timeout);
 83                                                    83 
 84         printf("Total ticks count: %d\n", tick     84         printf("Total ticks count: %d\n", ticked);
 85                                                    85 
 86         return EXIT_SUCCESS;                       86         return EXIT_SUCCESS;
 87 }                                                  87 }
 88                                                    88 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php