Skip to content

Commit bf08359

Browse files
committed
ALSA: timer: Replace tasklet with work
The tasklet is an old API that should be deprecated, usually can be converted to another decent API. In ALSA core timer API, the callbacks can be offlined to a tasklet when a flag is set in the timer backend. It can be achieved gracefully with a work queued in the high-prio system workqueue. This patch replaces the usage of tasklet in ALSA timer API with a simple work. Currently the tasklet feature is used only in the system timer and hrtimer backends, so both are patched to use the new flag name SNDRV_TIMER_HW_WORK, too. Link: https://lore.kernel.org/r/20200903104131.21097-3-tiwai@suse.de Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 68f86a9 commit bf08359

3 files changed

Lines changed: 15 additions & 15 deletions

File tree

‎include/sound/timer.h‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
#define SNDRV_TIMER_HW_STOP 0x00000002 /* call stop before start */
2222
#define SNDRV_TIMER_HW_SLAVE 0x00000004 /* only slave timer (variable resolution) */
2323
#define SNDRV_TIMER_HW_FIRST 0x00000008 /* first tick can be incomplete */
24-
#define SNDRV_TIMER_HW_TASKLET 0x00000010 /* timer is called from tasklet */
24+
#define SNDRV_TIMER_HW_WORK 0x00000010 /* timer is called from work */
2525

2626
#define SNDRV_TIMER_IFLG_SLAVE 0x00000001
2727
#define SNDRV_TIMER_IFLG_RUNNING 0x00000002
2828
#define SNDRV_TIMER_IFLG_START 0x00000004
2929
#define SNDRV_TIMER_IFLG_AUTO 0x00000008 /* auto restart */
30-
#define SNDRV_TIMER_IFLG_FAST 0x00000010 /* fast callback (do not use tasklet) */
30+
#define SNDRV_TIMER_IFLG_FAST 0x00000010 /* fast callback (do not use work) */
3131
#define SNDRV_TIMER_IFLG_CALLBACK 0x00000020 /* timer callback is active */
3232
#define SNDRV_TIMER_IFLG_EXCLUSIVE 0x00000040 /* exclusive owner - no more instances */
3333
#define SNDRV_TIMER_IFLG_EARLY_EVENT 0x00000080 /* write early event to the poll queue */
@@ -74,7 +74,7 @@ struct snd_timer {
7474
struct list_head active_list_head;
7575
struct list_head ack_list_head;
7676
struct list_head sack_list_head; /* slow ack list head */
77-
struct tasklet_struct task_queue;
77+
struct work_struct task_work;
7878
int max_instances; /* upper limit of timer instances */
7979
int num_instances; /* current number of timer instances */
8080
};
@@ -96,7 +96,7 @@ struct snd_timer_instance {
9696
unsigned long ticks; /* auto-load ticks when expired */
9797
unsigned long cticks; /* current ticks */
9898
unsigned long pticks; /* accumulated ticks for callback */
99-
unsigned long resolution; /* current resolution for tasklet */
99+
unsigned long resolution; /* current resolution for work */
100100
unsigned long lost; /* lost ticks */
101101
int slave_class;
102102
unsigned int slave_id;

‎sound/core/hrtimer.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ static int snd_hrtimer_stop(struct snd_timer *t)
114114
}
115115

116116
static const struct snd_timer_hardware hrtimer_hw __initconst = {
117-
.flags = SNDRV_TIMER_HW_AUTO | SNDRV_TIMER_HW_TASKLET,
117+
.flags = SNDRV_TIMER_HW_AUTO | SNDRV_TIMER_HW_WORK,
118118
.open = snd_hrtimer_open,
119119
.close = snd_hrtimer_close,
120120
.start = snd_hrtimer_start,

‎sound/core/timer.c‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -813,12 +813,12 @@ static void snd_timer_clear_callbacks(struct snd_timer *timer,
813813
}
814814

815815
/*
816-
* timer tasklet
816+
* timer work
817817
*
818818
*/
819-
static void snd_timer_tasklet(struct tasklet_struct *t)
819+
static void snd_timer_work(struct work_struct *work)
820820
{
821-
struct snd_timer *timer = from_tasklet(timer, t, task_queue);
821+
struct snd_timer *timer = container_of(work, struct snd_timer, task_work);
822822
unsigned long flags;
823823

824824
if (timer->card && timer->card->shutdown) {
@@ -843,7 +843,7 @@ void snd_timer_interrupt(struct snd_timer * timer, unsigned long ticks_left)
843843
unsigned long resolution;
844844
struct list_head *ack_list_head;
845845
unsigned long flags;
846-
int use_tasklet = 0;
846+
bool use_work = false;
847847

848848
if (timer == NULL)
849849
return;
@@ -884,7 +884,7 @@ void snd_timer_interrupt(struct snd_timer * timer, unsigned long ticks_left)
884884
--timer->running;
885885
list_del_init(&ti->active_list);
886886
}
887-
if ((timer->hw.flags & SNDRV_TIMER_HW_TASKLET) ||
887+
if ((timer->hw.flags & SNDRV_TIMER_HW_WORK) ||
888888
(ti->flags & SNDRV_TIMER_IFLG_FAST))
889889
ack_list_head = &timer->ack_list_head;
890890
else
@@ -919,11 +919,11 @@ void snd_timer_interrupt(struct snd_timer * timer, unsigned long ticks_left)
919919
snd_timer_process_callbacks(timer, &timer->ack_list_head);
920920

921921
/* do we have any slow callbacks? */
922-
use_tasklet = !list_empty(&timer->sack_list_head);
922+
use_work = !list_empty(&timer->sack_list_head);
923923
spin_unlock_irqrestore(&timer->lock, flags);
924924

925-
if (use_tasklet)
926-
tasklet_schedule(&timer->task_queue);
925+
if (use_work)
926+
queue_work(system_highpri_wq, &timer->task_work);
927927
}
928928
EXPORT_SYMBOL(snd_timer_interrupt);
929929

@@ -967,7 +967,7 @@ int snd_timer_new(struct snd_card *card, char *id, struct snd_timer_id *tid,
967967
INIT_LIST_HEAD(&timer->ack_list_head);
968968
INIT_LIST_HEAD(&timer->sack_list_head);
969969
spin_lock_init(&timer->lock);
970-
tasklet_setup(&timer->task_queue, snd_timer_tasklet);
970+
INIT_WORK(&timer->task_work, snd_timer_work);
971971
timer->max_instances = 1000; /* default limit per timer */
972972
if (card != NULL) {
973973
timer->module = card->module;
@@ -1200,7 +1200,7 @@ static int snd_timer_s_close(struct snd_timer *timer)
12001200

12011201
static const struct snd_timer_hardware snd_timer_system =
12021202
{
1203-
.flags = SNDRV_TIMER_HW_FIRST | SNDRV_TIMER_HW_TASKLET,
1203+
.flags = SNDRV_TIMER_HW_FIRST | SNDRV_TIMER_HW_WORK,
12041204
.resolution = 1000000000L / HZ,
12051205
.ticks = 10000000L,
12061206
.close = snd_timer_s_close,

0 commit comments

Comments
 (0)