Skip to content

Commit

Permalink
[ALSA] Fix schedule_timeout usage
Browse files Browse the repository at this point in the history
Use schedule_timeout_{,un}interruptible() instead of
set_current_state()/schedule_timeout() to reduce kernel size.  Also use
human-time conversion functions instead of hard-coded division to avoid
rounding issues.

Signed-off-by: Nishanth Aravamudan <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Takashi Iwai <[email protected]>
  • Loading branch information
Nishanth Aravamudan authored and Jaroslav Kysela committed Nov 4, 2005
1 parent d78bec2 commit 8433a50
Show file tree
Hide file tree
Showing 28 changed files with 51 additions and 112 deletions.
12 changes: 4 additions & 8 deletions sound/core/seq/seq_instr.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ void snd_seq_instr_list_free(snd_seq_kinstr_list_t **list_ptr)
spin_lock_irqsave(&list->lock, flags);
while (instr->use) {
spin_unlock_irqrestore(&list->lock, flags);
set_current_state(TASK_INTERRUPTIBLE);
schedule_timeout(1);
schedule_timeout_interruptible(1);
spin_lock_irqsave(&list->lock, flags);
}
spin_unlock_irqrestore(&list->lock, flags);
Expand Down Expand Up @@ -199,10 +198,8 @@ int snd_seq_instr_list_free_cond(snd_seq_kinstr_list_t *list,
while (flist) {
instr = flist;
flist = instr->next;
while (instr->use) {
set_current_state(TASK_INTERRUPTIBLE);
schedule_timeout(1);
}
while (instr->use)
schedule_timeout_interruptible(1);
if (snd_seq_instr_free(instr, atomic)<0)
snd_printk(KERN_WARNING "instrument free problem\n");
instr = next;
Expand Down Expand Up @@ -554,8 +551,7 @@ static int instr_free(snd_seq_kinstr_ops_t *ops,
instr->ops->notify(instr->ops->private_data, instr, SNDRV_SEQ_INSTR_NOTIFY_REMOVE);
while (instr->use) {
spin_unlock_irqrestore(&list->lock, flags);
set_current_state(TASK_INTERRUPTIBLE);
schedule_timeout(1);
schedule_timeout_interruptible(1);
spin_lock_irqsave(&list->lock, flags);
}
spin_unlock_irqrestore(&list->lock, flags);
Expand Down
3 changes: 1 addition & 2 deletions sound/core/seq/seq_lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ void snd_use_lock_sync_helper(snd_use_lock_t *lockp, const char *file, int line)
snd_printk(KERN_WARNING "seq_lock: timeout [%d left] in %s:%d\n", atomic_read(lockp), file, line);
break;
}
set_current_state(TASK_UNINTERRUPTIBLE);
schedule_timeout(1);
schedule_timeout_uninterruptible(1);
max_count--;
}
}
Expand Down
3 changes: 1 addition & 2 deletions sound/core/seq/seq_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,7 @@ int snd_seq_pool_done(pool_t *pool)
snd_printk(KERN_WARNING "snd_seq_pool_done timeout: %d cells remain\n", atomic_read(&pool->counter));
break;
}
set_current_state(TASK_UNINTERRUPTIBLE);
schedule_timeout(1);
schedule_timeout_uninterruptible(1);
max_count--;
}

Expand Down
3 changes: 1 addition & 2 deletions sound/i2c/cs8427.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,7 @@ static void snd_cs8427_reset(snd_i2c_device_t *cs8427)
snd_i2c_unlock(cs8427->bus);
if (!(data & CS8427_UNLOCK))
break;
set_current_state(TASK_UNINTERRUPTIBLE);
schedule_timeout(1);
schedule_timeout_uninterruptible(1);
}
snd_i2c_lock(cs8427->bus);
chip->regmap[CS8427_REG_CLOCKSOURCE] &= ~CS8427_RXDMASK;
Expand Down
6 changes: 2 additions & 4 deletions sound/isa/ad1848/ad1848_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,7 @@ static void snd_ad1848_mce_down(ad1848_t *chip)
snd_printk(KERN_ERR "mce_down - auto calibration time out (2)\n");
return;
}
set_current_state(TASK_INTERRUPTIBLE);
time = schedule_timeout(time);
time = schedule_timeout_interruptible(time);
spin_lock_irqsave(&chip->reg_lock, flags);
}
#if 0
Expand All @@ -257,8 +256,7 @@ static void snd_ad1848_mce_down(ad1848_t *chip)
snd_printk(KERN_ERR "mce_down - auto calibration time out (3)\n");
return;
}
set_current_state(TASK_INTERRUPTIBLE);
time = schedule_timeout(time);
time = schedule_timeout_interruptible(time);
spin_lock_irqsave(&chip->reg_lock, flags);
}
spin_unlock_irqrestore(&chip->reg_lock, flags);
Expand Down
3 changes: 1 addition & 2 deletions sound/isa/gus/gus_pcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,7 @@ static int snd_gf1_pcm_poke_block(snd_gus_card_t *gus, unsigned char *buf,
}
}
if (count > 0 && !in_interrupt()) {
set_current_state(TASK_INTERRUPTIBLE);
schedule_timeout(1);
schedule_timeout_interruptible(1);
if (signal_pending(current))
return -EAGAIN;
}
Expand Down
9 changes: 3 additions & 6 deletions sound/isa/sb/emu8000.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ static void __init
snd_emu8000_read_wait(emu8000_t *emu)
{
while ((EMU8000_SMALR_READ(emu) & 0x80000000) != 0) {
set_current_state(TASK_INTERRUPTIBLE);
schedule_timeout(1);
schedule_timeout_interruptible(1);
if (signal_pending(current))
break;
}
Expand All @@ -148,8 +147,7 @@ static void __init
snd_emu8000_write_wait(emu8000_t *emu)
{
while ((EMU8000_SMALW_READ(emu) & 0x80000000) != 0) {
set_current_state(TASK_INTERRUPTIBLE);
schedule_timeout(1);
schedule_timeout_interruptible(1);
if (signal_pending(current))
break;
}
Expand Down Expand Up @@ -437,8 +435,7 @@ size_dram(emu8000_t *emu)
for (i = 0; i < 10000; i++) {
if ((EMU8000_SMALW_READ(emu) & 0x80000000) == 0)
break;
set_current_state(TASK_INTERRUPTIBLE);
schedule_timeout(1);
schedule_timeout_interruptible(1);
if (signal_pending(current))
break;
}
Expand Down
3 changes: 1 addition & 2 deletions sound/isa/sb/emu8000_patch.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ static void
snd_emu8000_write_wait(emu8000_t *emu)
{
while ((EMU8000_SMALW_READ(emu) & 0x80000000) != 0) {
set_current_state(TASK_INTERRUPTIBLE);
schedule_timeout(1);
schedule_timeout_interruptible(1);
if (signal_pending(current))
break;
}
Expand Down
3 changes: 1 addition & 2 deletions sound/isa/sb/emu8000_pcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ snd_emu8000_write_wait(emu8000_t *emu, int can_schedule)
{
while ((EMU8000_SMALW_READ(emu) & 0x80000000) != 0) {
if (can_schedule) {
set_current_state(TASK_INTERRUPTIBLE);
schedule_timeout(1);
schedule_timeout_interruptible(1);
if (signal_pending(current))
break;
}
Expand Down
17 changes: 2 additions & 15 deletions sound/isa/sscape.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,19 +342,6 @@ static void soundscape_free(snd_card_t * c)
free_dma(sscape->chip->dma1);
}

/*
* Put this process into an idle wait-state for a certain number
* of "jiffies". The process can almost certainly be rescheduled
* while we're waiting, and so we must NOT be holding any spinlocks
* when we call this function. If we are then we risk DEADLOCK in
* SMP (Ha!) or pre-emptible kernels.
*/
static inline void sleep(long jiffs, int state)
{
set_current_state(state);
schedule_timeout(jiffs);
}

/*
* Tell the SoundScape to begin a DMA tranfer using the given channel.
* All locking issues are left to the caller.
Expand Down Expand Up @@ -392,7 +379,7 @@ static int obp_startup_ack(struct soundscape *s, unsigned timeout)
unsigned long flags;
unsigned char x;

sleep(1, TASK_INTERRUPTIBLE);
schedule_timeout_interruptible(1);

spin_lock_irqsave(&s->lock, flags);
x = inb(HOST_DATA_IO(s->io_base));
Expand All @@ -419,7 +406,7 @@ static int host_startup_ack(struct soundscape *s, unsigned timeout)
unsigned long flags;
unsigned char x;

sleep(1, TASK_INTERRUPTIBLE);
schedule_timeout_interruptible(1);

spin_lock_irqsave(&s->lock, flags);
x = inb(HOST_DATA_IO(s->io_base));
Expand Down
6 changes: 2 additions & 4 deletions sound/isa/wavefront/wavefront_synth.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,7 @@ static int
wavefront_sleep (int limit)

{
set_current_state(TASK_INTERRUPTIBLE);
schedule_timeout(limit);
schedule_timeout_interruptible(limit);

return signal_pending(current);
}
Expand Down Expand Up @@ -1788,8 +1787,7 @@ wavefront_should_cause_interrupt (snd_wavefront_t *dev,
outb (val,port);
spin_unlock_irq(&dev->irq_lock);
while (1) {
set_current_state(TASK_INTERRUPTIBLE);
if ((timeout = schedule_timeout(timeout)) == 0)
if ((timeout = schedule_timeout_interruptible(timeout)) == 0)
return;
if (dev->irq_ok)
return;
Expand Down
15 changes: 5 additions & 10 deletions sound/pci/ac97/ac97_codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1745,8 +1745,7 @@ static int ac97_reset_wait(ac97_t *ac97, int timeout, int with_modem)
if ((snd_ac97_read(ac97, AC97_REC_GAIN) & 0x7fff) == 0x0a05)
return 0;
}
set_current_state(TASK_UNINTERRUPTIBLE);
schedule_timeout(1);
schedule_timeout_uninterruptible(1);
} while (time_after_eq(end_time, jiffies));
return -ENODEV;
}
Expand Down Expand Up @@ -1992,8 +1991,7 @@ int snd_ac97_mixer(ac97_bus_t *bus, ac97_template_t *template, ac97_t **rac97)
do {
if ((snd_ac97_read(ac97, AC97_POWERDOWN) & 0x0f) == 0x0f)
goto __ready_ok;
set_current_state(TASK_UNINTERRUPTIBLE);
schedule_timeout(1);
schedule_timeout_uninterruptible(1);
} while (time_after_eq(end_time, jiffies));
snd_printk(KERN_WARNING "AC'97 %d analog subsections not ready\n", ac97->num);
}
Expand Down Expand Up @@ -2025,8 +2023,7 @@ int snd_ac97_mixer(ac97_bus_t *bus, ac97_template_t *template, ac97_t **rac97)
do {
if ((snd_ac97_read(ac97, AC97_EXTENDED_MSTATUS) & tmp) == tmp)
goto __ready_ok;
set_current_state(TASK_UNINTERRUPTIBLE);
schedule_timeout(1);
schedule_timeout_uninterruptible(1);
} while (time_after_eq(end_time, jiffies));
snd_printk(KERN_WARNING "MC'97 %d converters and GPIO not ready (0x%x)\n", ac97->num, snd_ac97_read(ac97, AC97_EXTENDED_MSTATUS));
}
Expand Down Expand Up @@ -2260,8 +2257,7 @@ void snd_ac97_resume(ac97_t *ac97)
do {
if (snd_ac97_read(ac97, AC97_MASTER) == 0x8101)
break;
set_current_state(TASK_UNINTERRUPTIBLE);
schedule_timeout(1);
schedule_timeout_uninterruptible(1);
} while (time_after_eq(end_time, jiffies));
/* FIXME: extra delay */
ac97->bus->ops->write(ac97, AC97_MASTER, 0x8000);
Expand All @@ -2273,8 +2269,7 @@ void snd_ac97_resume(ac97_t *ac97)
unsigned short val = snd_ac97_read(ac97, AC97_EXTENDED_MID);
if (val != 0xffff && (val & 1) != 0)
break;
set_current_state(TASK_UNINTERRUPTIBLE);
schedule_timeout(1);
schedule_timeout_uninterruptible(1);
} while (time_after_eq(end_time, jiffies));
}
__reset_ready:
Expand Down
12 changes: 4 additions & 8 deletions sound/pci/ali5451/ali5451.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,8 @@ static int snd_ali_codec_ready( ali_t *codec,
res = snd_ali_5451_peek(codec,port);
if (! (res & 0x8000))
return 0;
if (sched) {
set_current_state(TASK_UNINTERRUPTIBLE);
schedule_timeout(1);
}
if (sched)
schedule_timeout_uninterruptible(1);
} while (time_after_eq(end_time, jiffies));
snd_ali_5451_poke(codec, port, res & ~0x8000);
snd_printdd("ali_codec_ready: codec is not ready.\n ");
Expand All @@ -421,10 +419,8 @@ static int snd_ali_stimer_ready(ali_t *codec, int sched)
dwChk2 = snd_ali_5451_peek(codec, ALI_STIMER);
if (dwChk2 != dwChk1)
return 0;
if (sched) {
set_current_state(TASK_UNINTERRUPTIBLE);
schedule_timeout(1);
}
if (sched)
schedule_timeout_uninterruptible(1);
} while (time_after_eq(end_time, jiffies));
snd_printk(KERN_ERR "ali_stimer_read: stimer is not ready.\n");
return -EIO;
Expand Down
3 changes: 1 addition & 2 deletions sound/pci/atiixp.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,7 @@ static int snd_atiixp_update_bits(atiixp_t *chip, unsigned int reg,

/* delay for one tick */
#define do_delay() do { \
set_current_state(TASK_UNINTERRUPTIBLE); \
schedule_timeout(1); \
schedule_timeout_uninterruptible(1); \
} while (0)


Expand Down
3 changes: 1 addition & 2 deletions sound/pci/atiixp_modem.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,7 @@ static int snd_atiixp_update_bits(atiixp_t *chip, unsigned int reg,

/* delay for one tick */
#define do_delay() do { \
set_current_state(TASK_UNINTERRUPTIBLE); \
schedule_timeout(1); \
schedule_timeout_uninterruptible(1); \
} while (0)


Expand Down
6 changes: 2 additions & 4 deletions sound/pci/cs4281.c
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,7 @@ static void snd_cs4281_delay(unsigned int delay)
delay = 1;
end_time = jiffies + delay;
do {
set_current_state(TASK_UNINTERRUPTIBLE);
schedule_timeout(1);
schedule_timeout_uninterruptible(1);
} while (time_after_eq(end_time, jiffies));
} else {
udelay(delay);
Expand All @@ -533,8 +532,7 @@ static void snd_cs4281_delay(unsigned int delay)

static inline void snd_cs4281_delay_long(void)
{
set_current_state(TASK_UNINTERRUPTIBLE);
schedule_timeout(1);
schedule_timeout_uninterruptible(1);
}

static inline void snd_cs4281_pokeBA0(cs4281_t *chip, unsigned long offset, unsigned int val)
Expand Down
3 changes: 1 addition & 2 deletions sound/pci/ens1370.c
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,7 @@ static void snd_es1370_codec_write(ak4531_t *ak4531,
outw(ES_1370_CODEC_WRITE(reg, val), ES_REG(ensoniq, 1370_CODEC));
return;
}
set_current_state(TASK_UNINTERRUPTIBLE);
schedule_timeout(1);
schedule_timeout_uninterruptible(1);
} while (time_after(end_time, jiffies));
snd_printk(KERN_ERR "codec write timeout, status = 0x%x\n", inl(ES_REG(ensoniq, STATUS)));
}
Expand Down
9 changes: 3 additions & 6 deletions sound/pci/fm801.c
Original file line number Diff line number Diff line change
Expand Up @@ -1303,8 +1303,7 @@ static int __devinit snd_fm801_create(snd_card_t * card,
do {
if ((inw(FM801_REG(chip, AC97_CMD)) & (3<<8)) == (1<<8))
goto __ac97_secondary;
set_current_state(TASK_UNINTERRUPTIBLE);
schedule_timeout(1);
schedule_timeout_uninterruptible(1);
} while (time_after(timeout, jiffies));
snd_printk(KERN_ERR "Primary AC'97 codec not found\n");
snd_fm801_free(chip);
Expand All @@ -1329,8 +1328,7 @@ static int __devinit snd_fm801_create(snd_card_t * card,
goto __ac97_ok;
}
}
set_current_state(TASK_UNINTERRUPTIBLE);
schedule_timeout(1);
schedule_timeout_uninterruptible(1);
} while (time_after(timeout, jiffies));
}

Expand All @@ -1343,8 +1341,7 @@ static int __devinit snd_fm801_create(snd_card_t * card,
do {
if ((inw(FM801_REG(chip, AC97_CMD)) & (3<<8)) == (1<<8))
goto __ac97_ok;
set_current_state(TASK_UNINTERRUPTIBLE);
schedule_timeout(1);
schedule_timeout_uninterruptible(1);
} while (time_after(timeout, jiffies));
snd_printk(KERN_ERR "Primary AC'97 codec not responding\n");
snd_fm801_free(chip);
Expand Down
3 changes: 1 addition & 2 deletions sound/pci/ice1712/pontis.c
Original file line number Diff line number Diff line change
Expand Up @@ -794,8 +794,7 @@ static int __devinit pontis_init(ice1712_t *ice)
/* initialize WM8776 codec */
for (i = 0; i < ARRAY_SIZE(wm_inits); i += 2)
wm_put(ice, wm_inits[i], wm_inits[i+1]);
set_current_state(TASK_UNINTERRUPTIBLE);
schedule_timeout(1);
schedule_timeout_uninterruptible(1);
for (i = 0; i < ARRAY_SIZE(wm_inits2); i += 2)
wm_put(ice, wm_inits2[i], wm_inits2[i+1]);

Expand Down
3 changes: 1 addition & 2 deletions sound/pci/intel8x0.c
Original file line number Diff line number Diff line change
Expand Up @@ -2144,8 +2144,7 @@ static void do_ali_reset(intel8x0_t *chip)
}

#define do_delay(chip) do {\
set_current_state(TASK_UNINTERRUPTIBLE);\
schedule_timeout(1);\
schedule_timeout_uninterruptible(1);\
} while (0)

static int snd_intel8x0_ich_chip_init(intel8x0_t *chip, int probing)
Expand Down
3 changes: 1 addition & 2 deletions sound/pci/intel8x0m.c
Original file line number Diff line number Diff line change
Expand Up @@ -890,8 +890,7 @@ static int __devinit snd_intel8x0_mixer(intel8x0_t *chip, int ac97_clock)
*/

#define do_delay(chip) do {\
set_current_state(TASK_UNINTERRUPTIBLE);\
schedule_timeout(1);\
schedule_timeout_uninterruptible(1);\
} while (0)

static int snd_intel8x0m_ich_chip_init(intel8x0_t *chip, int probing)
Expand Down
Loading

0 comments on commit 8433a50

Please sign in to comment.