mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-19 05:37:54 +00:00
Remove gems/magic_ring_buffer.h
Since its introduction four years ago, the utility remained largely unused. Fixes #4403
This commit is contained in:
parent
d4d875f2e6
commit
62b4871c5c
@ -1,155 +0,0 @@
|
||||
/*
|
||||
* \brief Region magic ring buffer
|
||||
* \author Emery Hemingway
|
||||
* \date 2018-02-01
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2018 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU Affero General Public License version 3.
|
||||
*/
|
||||
|
||||
#ifndef _INCLUDE__GEMS__RING_BUFFER_H_
|
||||
#define _INCLUDE__GEMS__RING_BUFFER_H_
|
||||
|
||||
/* Genode includes */
|
||||
#include <base/attached_ram_dataspace.h>
|
||||
#include <rm_session/connection.h>
|
||||
#include <region_map/client.h>
|
||||
#include <dataspace/client.h>
|
||||
|
||||
namespace Genode {
|
||||
template <typename TYPE>
|
||||
struct Magic_ring_buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* A ring buffer that uses a single dataspace mapped twice in consecutive
|
||||
* regions. This allows any operation that is less or equal to the size of
|
||||
* the buffer to be read or written in a single pass.
|
||||
*/
|
||||
template <typename TYPE>
|
||||
class Genode::Magic_ring_buffer
|
||||
{
|
||||
private:
|
||||
|
||||
Magic_ring_buffer(Magic_ring_buffer const &);
|
||||
Magic_ring_buffer &operator = (Magic_ring_buffer const &);
|
||||
|
||||
Genode::Env &_env;
|
||||
|
||||
Ram_dataspace_capability _buffer_ds;
|
||||
|
||||
size_t const _ds_size = Dataspace_client(_buffer_ds).size();
|
||||
size_t const _capacity = _ds_size / sizeof(TYPE);
|
||||
|
||||
Rm_connection _rm_connection { _env };
|
||||
|
||||
/* create region map (reserve address space) */
|
||||
Region_map_client _rm { _rm_connection.create(_ds_size*2) };
|
||||
|
||||
/* attach map to global region map */
|
||||
TYPE *_buffer = (TYPE *)_env.rm().attach(_rm.dataspace());
|
||||
|
||||
size_t _wpos = 0;
|
||||
size_t _rpos = 0;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Ring capacity of TYPE items
|
||||
*/
|
||||
size_t capacity() { return _capacity; }
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* \param TYPE Ring item type, size of type must be a
|
||||
* power of two and less than the page size
|
||||
*
|
||||
* \param env Env for dataspace allocation and mapping
|
||||
* \param num_bytes Size of ring in bytes, may be rounded up
|
||||
* to the next page boundry
|
||||
*
|
||||
* \throw Region_map::Region_conflict
|
||||
* \throw Out_of_ram
|
||||
* \throw Out_of_caps
|
||||
*
|
||||
*/
|
||||
Magic_ring_buffer(Genode::Env &env, size_t num_bytes)
|
||||
: _env(env), _buffer_ds(_env.pd().alloc(num_bytes))
|
||||
{
|
||||
if (_ds_size % sizeof(TYPE)) {
|
||||
error("Magic_ring_buffer cannot hold unaligned TYPE");
|
||||
throw Exception();
|
||||
}
|
||||
|
||||
/* attach buffer dataspace twice into reserved region */
|
||||
_rm.attach_at(_buffer_ds, 0, _ds_size);
|
||||
_rm.attach_at(_buffer_ds, _ds_size, _ds_size);
|
||||
}
|
||||
|
||||
~Magic_ring_buffer()
|
||||
{
|
||||
/* detach dataspace from reserved region */
|
||||
_rm.detach((addr_t)_ds_size);
|
||||
_rm.detach((addr_t)0);
|
||||
|
||||
/* detach reserved region */
|
||||
_env.rm().detach((addr_t)_buffer);
|
||||
|
||||
/* free buffer */
|
||||
_env.ram().free(_buffer_ds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Number of items that may be written to ring
|
||||
*/
|
||||
size_t write_avail() const
|
||||
{
|
||||
if (_wpos > _rpos)
|
||||
return ((_rpos - _wpos + _capacity) % _capacity) - 2;
|
||||
else if (_wpos < _rpos)
|
||||
return _rpos - _wpos;
|
||||
else
|
||||
return _capacity - 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Number of items that may be read from ring
|
||||
*/
|
||||
size_t read_avail() const
|
||||
{
|
||||
if (_wpos > _rpos)
|
||||
return _wpos - _rpos;
|
||||
else
|
||||
return (_wpos - _rpos + _capacity) % _capacity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pointer to ring write address
|
||||
*/
|
||||
TYPE *write_addr() const { return &_buffer[_wpos]; }
|
||||
|
||||
/**
|
||||
* Pointer to ring read address
|
||||
*/
|
||||
TYPE *read_addr() const { return &_buffer[_rpos]; }
|
||||
|
||||
/**
|
||||
* Advance the ring write pointer
|
||||
*/
|
||||
void fill(size_t items) {
|
||||
_wpos = (_wpos+items) % _capacity; }
|
||||
|
||||
/**
|
||||
* Advance the ring read pointer
|
||||
*/
|
||||
void drain(size_t items) {
|
||||
_rpos = (_rpos+items) % _capacity; }
|
||||
};
|
||||
|
||||
#endif
|
@ -1 +0,0 @@
|
||||
Test of Genodes magic-ring-buffer implementation.
|
@ -1,2 +0,0 @@
|
||||
_/src/init
|
||||
_/src/test-magic_ring_buffer
|
@ -1 +0,0 @@
|
||||
2022-01-18 b93a983aa7d731e2235d65498abc3e301f163578
|
@ -1,29 +0,0 @@
|
||||
<runtime ram="32M" caps="1000" binary="init">
|
||||
|
||||
<events>
|
||||
<timeout meaning="failed" sec="10" />
|
||||
<log meaning="succeeded">child "test-magic_ring_buffer" exited with exit value 0</log>
|
||||
<log meaning="failed">Error: </log>
|
||||
</events>
|
||||
|
||||
<content>
|
||||
<rom label="ld.lib.so"/>
|
||||
<rom label="test-magic_ring_buffer"/>
|
||||
</content>
|
||||
|
||||
<config>
|
||||
<parent-provides>
|
||||
<service name="CPU"/>
|
||||
<service name="LOG"/>
|
||||
<service name="PD"/>
|
||||
<service name="RM"/>
|
||||
<service name="ROM"/>
|
||||
</parent-provides>
|
||||
<default-route>
|
||||
<any-service> <parent/> </any-service>
|
||||
</default-route>
|
||||
<start name="test-magic_ring_buffer" caps="64">
|
||||
<resource name="RAM" quantum="2M"/>
|
||||
</start>
|
||||
</config>
|
||||
</runtime>
|
@ -1,3 +0,0 @@
|
||||
SRC_DIR = src/test/magic_ring_buffer
|
||||
|
||||
include $(GENODE_DIR)/repos/base/recipes/src/content.inc
|
@ -1 +0,0 @@
|
||||
2022-01-18 bb72eddaf80e7d0f98c6c954f176acd4e0963bd6
|
@ -1,2 +0,0 @@
|
||||
base
|
||||
gems
|
@ -689,7 +689,6 @@ set default_test_pkgs {
|
||||
test-libc_vfs_ram
|
||||
test-log
|
||||
test-lx_block
|
||||
test-magic_ring_buffer
|
||||
test-mmio
|
||||
test-new_delete
|
||||
test-nic_loopback
|
||||
|
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* \brief Magic ring buffer test
|
||||
* \author Emery Hemingway
|
||||
* \date 2018-04-04
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2018 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU Affero General Public License version 3.
|
||||
*/
|
||||
|
||||
/* Genode includes */
|
||||
#include <base/component.h>
|
||||
#include <base/log.h>
|
||||
|
||||
/* gems includes */
|
||||
#include <gems/magic_ring_buffer.h>
|
||||
|
||||
void Component::construct(Genode::Env &env)
|
||||
{
|
||||
using namespace Genode;
|
||||
|
||||
Magic_ring_buffer<int> ring_buffer(env, 4097);
|
||||
|
||||
log("--- magic ring buffer test, ", ring_buffer.capacity(), " int ring ---");
|
||||
|
||||
size_t const count = ring_buffer.capacity()/3;
|
||||
|
||||
size_t total = 0;
|
||||
|
||||
for (size_t j = 0; j < 99; ++j) {
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
ring_buffer.write_addr()[i] = (int)i;
|
||||
}
|
||||
|
||||
ring_buffer.fill(count);
|
||||
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
if (ring_buffer.read_addr()[i] != (int)i) {
|
||||
error("ring buffer corruption, ",
|
||||
ring_buffer.read_addr()[i], " != ", i);
|
||||
env.parent().exit((int)(total + i));
|
||||
return;
|
||||
}
|
||||
}
|
||||
ring_buffer.drain(count);
|
||||
|
||||
total += count;
|
||||
}
|
||||
|
||||
log("--- test complete, ", total, " ints passed through ring ---");
|
||||
env.parent().exit(0);
|
||||
}
|
||||
|
@ -1,3 +0,0 @@
|
||||
TARGET = test-magic_ring_buffer
|
||||
SRC_CC = main.cc
|
||||
LIBS = base
|
Loading…
Reference in New Issue
Block a user