Board.KolibriOS.org
http://board.kolibrios.org/

Ring buffers in userland
http://board.kolibrios.org/viewtopic.php?f=1&t=4189
Page 1 of 1

Author:  hidnplayr [ Mon May 04, 2020 6:44 pm ]
Post subject:  Ring buffers in userland

Hello fellow kernel-developers,

Does anyone know the steps required to implement ring-buffers for the application level?
I studied the kernel code a bit, but am afraid I don't quite understood the inner working of user heap.

Author:  dunkaist [ Mon May 04, 2020 7:50 pm ]
Post subject:  Re: Ring buffers in userland

Hi hidnplayr,
hidnplayr wrote:
Does anyone know
Not me :D

I'm not sure I understood your question. Do you want something like io_uring?

Author:  hidnplayr [ Mon May 04, 2020 8:05 pm ]
Post subject:  Re: Ring buffers in userland

https://en.wikipedia.org/wiki/Circular_ ... timization

Analog to create_ring_buffer in kernel, but accessible from application/libraries.

Author:  dunkaist [ Mon May 04, 2020 11:38 pm ]
Post subject:  Re: Ring buffers in userland

After reading this post I managed to get two adjacent virtual pages mapped to the same physical page, RW accessible from the application:
Code:
stdcall user_alloc, 0x2000
<-lin

call alloc_page
<-phys

stdcall map_page, lin, phys, PG_UWR
stdcall map_page, lin+0x1000, phys, PG_UWR


May be it makes sense to create create_ring_buffer_user and create_ring_buffer_common and move most part of create_ring_buffer to the latter one.

Author:  hidnplayr [ Tue May 05, 2020 8:20 pm ]
Post subject:  Re: Ring buffers in userland

dunkaist wrote:
After reading this post I managed to get two adjacent virtual pages mapped to the same physical page, RW accessible from the application:
Code:
stdcall user_alloc, 0x2000
<-lin

call alloc_page
<-phys

stdcall map_page, lin, phys, PG_UWR
stdcall map_page, lin+0x1000, phys, PG_UWR


May be it makes sense to create create_ring_buffer_user and create_ring_buffer_common and move most part of create_ring_buffer to the latter one.


Problem I see is that "stdcall user_alloc" gives us virtual memory that is already mapped to physical memory.
(And didn't find yet how/where it is mapped.)

Also, how to undo everything when we're done?

Author:  dunkaist [ Wed May 06, 2020 5:44 am ]
Post subject:  Re: Ring buffers in userland

hidnplayr wrote:
Problem I see is that "stdcall user_alloc" gives us virtual memory that is already mapped to physical memory.
(And didn't find yet how/where it is mapped.)

Doesn't user_alloc allocates memory lazily, i.e. only virtual pages immediately, physical pages in PF handler?
If this is the case, then it is clear why you didn't find where user_alloc works with physical pages.

hidnplayr wrote:
Also, how to undo everything when we're done?

Again, I'm just interpreting this post.
I see that user_free calls free_page too. Isn't it enough?

Author:  hidnplayr [ Wed May 06, 2020 7:10 pm ]
Post subject:  Re: Ring buffers in userland

dunkaist wrote:
hidnplayr wrote:
Problem I see is that "stdcall user_alloc" gives us virtual memory that is already mapped to physical memory.
(And didn't find yet how/where it is mapped.)

Doesn't user_alloc allocates memory lazily, i.e. only virtual pages immediately, physical pages in PF handler?
If this is the case, then it is clear why you didn't find where user_alloc works with physical pages.


It seems you are right. Allocation is done in "page_fault_handler" in memory.inc
It explains the magic bit flag '2' sometimes referred to in the code as 'reserved'.

Thanks!

Page 1 of 1 All times are UTC+03:00
Powered by phpBB® Forum Software © phpBB Limited
https://www.phpbb.com/