Board.KolibriOS.org

Official KolibriOS board
It is currently Mon Nov 30, 2020 8:15 pm

All times are UTC+03:00




Post new topic  Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Ring buffers in userland
PostPosted: Mon May 04, 2020 6:44 pm 
Offline
Mentor/Kernel Developer
User avatar

Joined: Fri Jun 30, 2006 9:01 am
Posts: 1276
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.

_________________
"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." Albert Einstein


Top
   
PostPosted: Mon May 04, 2020 7:50 pm 
Offline
Mentor
User avatar

Joined: Mon Oct 19, 2009 10:58 am
Posts: 575
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?


Top
   
PostPosted: Mon May 04, 2020 8:05 pm 
Offline
Mentor/Kernel Developer
User avatar

Joined: Fri Jun 30, 2006 9:01 am
Posts: 1276
https://en.wikipedia.org/wiki/Circular_ ... timization

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

_________________
"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." Albert Einstein


Top
   
PostPosted: Mon May 04, 2020 11:38 pm 
Offline
Mentor
User avatar

Joined: Mon Oct 19, 2009 10:58 am
Posts: 575
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.


Top
   
PostPosted: Tue May 05, 2020 8:20 pm 
Offline
Mentor/Kernel Developer
User avatar

Joined: Fri Jun 30, 2006 9:01 am
Posts: 1276
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?

_________________
"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." Albert Einstein


Top
   
PostPosted: Wed May 06, 2020 5:44 am 
Offline
Mentor
User avatar

Joined: Mon Oct 19, 2009 10:58 am
Posts: 575
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?


Top
   
PostPosted: Wed May 06, 2020 7:10 pm 
Offline
Mentor/Kernel Developer
User avatar

Joined: Fri Jun 30, 2006 9:01 am
Posts: 1276
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!

_________________
"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." Albert Einstein


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 7 posts ] 

All times are UTC+03:00


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited