Re: real-time process

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>>>>> "Momchil" == Momchil Velikov <velco@fadata.bg> writes:

>>>>> "Nagaraj" == Nagaraj  <nagaraj@smartyantra.com> writes:
Momchil> FWIW, the problem is the classic producer-consumer problem with
Momchil> solutions described in _any_ OS textbook.

Momchil> Thus, the right solution would be to use semaphores.  But, AFAIK,
Momchil> there are no semaphores shared between the userspace and the kernel.

Momchil> Probably futexes can do the work.

Alternatively (and better),

Have the driver allocate 2 buffers and mmap() them into the process.
Have the driver create 2 semaphores (initially zero) and let the app
post and wait on them with ioctls.

void *buf[2];

buf [0] = mmap (fd, ...);
buf [1] = buf [0] + HALF_BUFFER_SIZE; /* GCC extension :) */

no = 0;
while (!done ())
{
        /* Let the driver know a buffer is available. DMA starts
           if not started already.  */
        ioctl (fd, POSTSEM_0);

        /* Wait until DMA interrupts and the interrupt handler signals the
           semaphore.  Driver continues filling the other buffer.  */
        ioctl (fd, WAITSEM_1);

        /* Data is in buffer, no copying needed.  */
        do_stuff (buf [no]);

        /* Switch buffers.  */
        no = !no;   
}

One can add buffers to compensate for jitter. On a real-time OS two
buffers ought to be enough.  Ok ?

~velco
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux