Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: Ivan Orlov <ivan.orlov0322@gmail.com>
To: Christophe JAILLET <christophe.jaillet@wanadoo.fr>,
	perex@perex.cz, tiwai@suse.com, corbet@lwn.net,
	broonie@kernel.org, shuah@kernel.org
Cc: linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org,
	linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
	aholzinger@gmx.de
Subject: Re: [PATCH 3/4] ALSA: timer: Introduce virtual userspace-driven timers
Date: Sun, 28 Jul 2024 09:51:24 +0100	[thread overview]
Message-ID: <3ab0aa72-4f89-4911-8546-ce17f362c981@gmail.com> (raw)
In-Reply-To: <0576f5dd-656b-4085-8c8d-b0f845875f0f@wanadoo.fr>

On 7/28/24 07:59, Christophe JAILLET wrote:
> Le 26/07/2024 à 09:47, Ivan Orlov a écrit :
>> Implement two ioctl calls in order to support virtual userspace-driven
>> ALSA timers.
>>
>> The first ioctl is SNDRV_TIMER_IOCTL_CREATE, which gets the
>> snd_utimer_info struct as a parameter and returns a file descriptor of
>> a virtual timer. It also updates the `id` field of the snd_utimer_info
>> struct, which provides a unique identifier for the timer (basically,
>> the subdevice number which can be used when creating timer instances).
>>
>> This patch also introduces a tiny id allocator for the userspace-driven
>> timers, which guarantees that we don't have more than 128 of them in the
>> system.
>>
>> Another ioctl is SNDRV_TIMER_IOCTL_TRIGGER, which allows us to trigger
>> the virtual timer (and calls snd_timer_interrupt for the timer under
>> the hood), causing all of the timer instances binded to this timer to
>> execute their callbacks.
>>
>> The maximum amount of ticks available for the timer is 1 for the sake of
>> simplification of the userspace API. 'start', 'stop', 'open' and 'close'
>> callbacks for the userspace-driven timers are empty since we don't
>> really do any hardware initialization here.
>>
>> Suggested-by: Axel Holzinger <aholzinger@gmx.de>
>> Signed-off-by: Ivan Orlov <ivan.orlov0322@gmail.com>
>> ---
> 
> ...
> 
>> +#ifdef CONFIG_SND_UTIMER
>> +/*
>> + * Since userspace-driven timers are passed to userspace, we need to 
>> have an identifier
>> + * which will allow us to use them (basically, the subdevice number 
>> of udriven timer).
>> + *
>> + * We have a pool of SNDRV_UTIMERS_MAX_COUNT ids from 0 to 
>> (SNDRV_UTIMERS_MAX_COUNT - 1).
>> + * When we take one of them, the corresponding entry in 
>> snd_utimer_ids becomes true.
>> + */
>> +static bool snd_utimer_ids[SNDRV_UTIMERS_MAX_COUNT];
>> +
>> +static void snd_utimer_put_id(struct snd_utimer *utimer)
>> +{
>> +    int timer_id = utimer->id;
>> +
>> +    snd_BUG_ON(timer_id < 0 || timer_id >= SNDRV_UTIMERS_MAX_COUNT);
>> +    snd_utimer_ids[timer_id] = false;
>> +}
>> +
>> +static int snd_utimer_take_id(void)
>> +{
>> +    size_t i;
>> +
>> +    for (i = 0; i < SNDRV_UTIMERS_MAX_COUNT; i++) {
>> +        if (!snd_utimer_ids[i]) {
>> +            snd_utimer_ids[i] = true;
>> +            return i;
>> +        }
>> +    }
>> +
>> +    return -EBUSY;
>> +}
> 
> Also the bitmap API could be useful here.
> 

Awesome, will use it in V2.

Thank you!


-- 
Kind regards,
Ivan Orlov


  reply	other threads:[~2024-07-28  8:51 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-26  7:47 [PATCH 0/4] Introduce userspace-driven ALSA timers Ivan Orlov
2024-07-26  7:47 ` [PATCH 1/4] ALSA: aloop: Allow using global timers Ivan Orlov
2024-07-26  7:47 ` [PATCH 2/4] Docs/sound: Add documentation for userspace-driven ALSA timers Ivan Orlov
2024-07-26  7:47 ` [PATCH 3/4] ALSA: timer: Introduce virtual userspace-driven timers Ivan Orlov
2024-07-28  6:52   ` Christophe JAILLET
2024-07-28  8:49     ` Ivan Orlov
2024-07-28  6:59   ` Christophe JAILLET
2024-07-28  8:51     ` Ivan Orlov [this message]
2024-07-28  9:30       ` Christophe JAILLET
2024-07-28  9:42         ` Ivan Orlov
2024-07-28 10:29           ` Christophe JAILLET
2024-07-28 11:54             ` Ivan Orlov
2024-07-26  7:47 ` [PATCH 4/4] selftests: ALSA: Cover userspace-driven timers with test Ivan Orlov
2024-07-28  6:10   ` kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3ab0aa72-4f89-4911-8546-ce17f362c981@gmail.com \
    --to=ivan.orlov0322@gmail.com \
    --cc=aholzinger@gmx.de \
    --cc=broonie@kernel.org \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=corbet@lwn.net \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=shuah@kernel.org \
    --cc=tiwai@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox