Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 3934 → Rev 3912

/branches/network/uspace/srv/net/tl/tcp/tcp_module.c
69,11 → 69,8
tcp_globals.networking_phone = connect_to_service( SERVICE_NETWORKING );
tcp_globals.ip_phone = bind_service( SERVICE_IP, IPPROTO_TCP, 0, 0, client_connection );
ERROR_PROPAGATE( pm_init());
if( ERROR_OCCURRED( tcp_initialize())
|| ERROR_OCCURRED( REGISTER_ME( SERVICE_TCP, & phonehash ))){
pm_destroy();
return ERROR_CODE;
}
ERROR_PROPAGATE( tcp_initialize());
ERROR_PROPAGATE( REGISTER_ME( SERVICE_TCP, & phonehash ));
 
async_manager();
 
/branches/network/uspace/srv/net/structures/packet/packet.c
36,7 → 36,6
*/
 
#include <errno.h>
#include <futex.h>
#include <malloc.h>
//#include <stdio.h>
#include <string.h>
88,13 → 87,10
/** Packet map global data.
*/
static struct{
/** Safety lock.
* Used as a&nbsp;mutex.
*/
futex_t lock;
// TODO lock
/** Packet map.
*/
gpm_t packet_map;
gpm_t packet_map;
} pm_globals;
 
GENERIC_FIELD_IMPLEMENT( gpm, packet_map_t );
105,34 → 101,17
}
 
int pm_init( void ){
ERROR_DECLARE;
 
// start locked
futex_initialize( & pm_globals.lock, 0 );
ERROR_PROPAGATE( gpm_initialize( & pm_globals.packet_map ));
// release the lock
futex_up( & pm_globals.lock );
return EOK;
return gpm_initialize( & pm_globals.packet_map );
}
 
packet_t pm_find( packet_id_t packet_id ){
packet_map_ref map;
packet_t packet;
 
if( ! packet_id ) return NULL;
futex_down( & pm_globals.lock );
if( packet_id > PACKET_MAP_SIZE * gpm_count( & pm_globals.packet_map )){
futex_up( & pm_globals.lock );
return NULL;
}
if( packet_id > PACKET_MAP_SIZE * gpm_count( & pm_globals.packet_map )) return NULL;
map = gpm_get_index( & pm_globals.packet_map, PACKET_MAP_PAGE( packet_id ));
if( ! map ){
futex_up( & pm_globals.lock );
return NULL;
}
packet = ( * map )[ PACKET_MAP_INDEX( packet_id ) ];
futex_up( & pm_globals.lock );
return packet;
if( ! map ) return NULL;
return ( * map )[ PACKET_MAP_INDEX( packet_id ) ];
}
 
int pm_add( packet_t packet ){
140,27 → 119,21
 
packet_map_ref map;
 
if( ! packet_is_valid( packet )) return EINVAL;
futex_down( & pm_globals.lock );
if(( ! packet_is_valid( packet )) || ( gpm_count( & pm_globals.packet_map ) < 0 )) return EINVAL;
if( PACKET_MAP_PAGE( packet->packet_id ) < gpm_count( & pm_globals.packet_map )){
map = gpm_get_index( & pm_globals.packet_map, PACKET_MAP_PAGE( packet->packet_id ));
}else{
do{
map = ( packet_map_ref ) malloc( sizeof( packet_map_t ));
if( ! map ){
futex_up( & pm_globals.lock );
return ENOMEM;
}
if( ! map ) return ENOMEM;
memset( map, 0, sizeof( packet_map_t ));
if(( ERROR_CODE = gpm_add( & pm_globals.packet_map, map )) < 0 ){
free( map );
futex_up( & pm_globals.lock );
return ERROR_CODE;
}
}while( PACKET_MAP_PAGE( packet->packet_id ) >= gpm_count( & pm_globals.packet_map ));
}
( * map )[ PACKET_MAP_INDEX( packet->packet_id ) ] = packet;
futex_up( & pm_globals.lock );
return EOK;
}
 
170,7 → 143,6
packet_map_ref map;
packet_t packet;
 
futex_down( & pm_globals.lock );
count = gpm_count( & pm_globals.packet_map );
while( count > 0 ){
map = gpm_get_index( & pm_globals.packet_map, count - 1 );
182,7 → 154,6
}
}
gpm_destroy( & pm_globals.packet_map );
// leave locked
}
 
packet_t pq_add( packet_t first, packet_t packet, int order, size_t metric ){
/branches/network/uspace/srv/net/structures/packet/packet_client.h
36,8 → 36,6
* To function correctly, initialization of the packet map by the pm_init() function has to happen at the first place.
* The module should not send the packet messages to the packet server but use the functions provided.
* The packet map should be released by the pm_destroy() function during the module termination.
* The packets and the packet queues can't be locked at all.
* The processing modules should process them sequentially -&nbsp;by passing the packets to the next module and stopping using the passed ones.
* @see packet.h
*/
 
/branches/network/uspace/srv/net/structures/packet/packet_server.c
34,10 → 34,9
* Packet server implementation.
*/
 
#include <async.h>
#include <align.h>
#include <async.h>
#include <errno.h>
#include <futex.h>
//#include <stdio.h>
#include <unistd.h>
 
81,9 → 80,6
/** Packet server global data.
*/
static struct{
/** Safety lock.
*/
futex_t lock;
/** Free packet queues.
*/
packet_t free[ FREE_QUEUES_COUNT ];
96,7 → 92,6
*/
unsigned int count;
} ps_globals = {
{ 1 },
{ NULL, NULL, NULL, NULL, NULL, NULL, NULL },
{ PAGE_SIZE, PAGE_SIZE * 2, PAGE_SIZE * 4, PAGE_SIZE * 8, PAGE_SIZE * 16, PAGE_SIZE * 32, PAGE_SIZE * 64 },
0
103,7 → 98,6
};
 
/** Releases the packet and returns it to the appropriate free packet queue.
* Should be used only when the global data are locked.
* @param packet The packet to be released. Input parameter.
*/
void packet_release( packet_t packet );
111,7 → 105,6
/** Returns the packet of dimensions at least as given.
* Tries to reuse free packets first.
* Creates a&nbsp;new packet aligned to the memory page size if none available.
* Locks the global data during its processing.
* @param owner The new owner of the packet. Input parameter.
* @param addr_len The source and destination addresses maximal length in bytes. Input parameter.
* @param max_prefix The maximal prefix length in bytes. Input parameter.
123,7 → 116,6
packet_t packet_get( services_t owner, size_t addr_len, size_t max_prefix, size_t max_content, size_t max_suffix );
 
/** Creates a&nbsp;new packet of dimensions at least as given.
* Should be used only when the global data are locked.
* @param length The total length of the packet, including the header, the addresses and the data of the packet. Input parameter.
* @param owner The new owner of the packet. Input parameter.
* @param addr_len The source and destination addresses maximal length in bytes. Input parameter.
189,9 → 181,7
case NET_PACKET_RELEASE:
packet = pm_find( IPC_GET_ID( call ));
if( ! packet_is_valid( packet )) return ENOENT;
futex_down( & ps_globals.lock );
pq_destroy( packet, packet_release );
futex_up( & ps_globals.lock );
return EOK;
}
return ENOTSUP;
210,7 → 200,6
size_t length;
 
length = ALIGN_UP( sizeof( struct packet ) + 2 * addr_len + max_prefix + max_content + max_suffix, PAGE_SIZE );
futex_down( & ps_globals.lock );
for( index = 0; index < FREE_QUEUES_COUNT - 1; ++ index ){
if( length <= ps_globals.sizes[ index ] ){
packet = ps_globals.free[ index ];
219,14 → 208,11
}
if( packet ){
packet_init( packet, owner, addr_len, max_prefix, max_content, max_suffix );
futex_up( & ps_globals.lock );
return packet;
}
}
}
packet = packet_create( length, owner, addr_len, max_prefix, max_content, max_suffix );
futex_up( & ps_globals.lock );
return packet;
return packet_create( length, owner, addr_len, max_prefix, max_content, max_suffix );
}
 
packet_t packet_create( size_t length, services_t owner, size_t addr_len, size_t max_prefix, size_t max_content, size_t max_suffix ){
234,7 → 220,6
 
packet_t packet;
 
// already locked
packet = ( packet_t ) mmap( NULL, length, PROTO_READ | PROTO_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0 );
if( packet == MAP_FAILED ) return NULL;
++ ps_globals.count;
/branches/network/uspace/srv/net/networking/networking.c
232,16 → 232,11
ipcarg_t phonehash;
 
async_set_client_connection( client_connection );
ERROR_PROPAGATE( networking_initialize());
ERROR_PROPAGATE( REGISTER_ME( SERVICE_NETWORKING, & phonehash ));
ERROR_PROPAGATE( pm_init());
if( ERROR_OCCURRED( networking_initialize())
|| ERROR_OCCURRED( REGISTER_ME( SERVICE_NETWORKING, & phonehash ))){
pm_destroy();
return ERROR_CODE;
}
 
async_manager();
 
pm_destroy();
return EOK;
}
 
/branches/network/uspace/srv/net/il/arp/arp_module.c
46,8 → 46,6
#include "../../err.h"
#include "../../modules.h"
 
#include "../../structures/packet/packet.h"
 
#include "arp.h"
#include "arp_module.h"
 
84,16 → 82,11
 
async_set_client_connection( client_connection );
arp_globals.networking_phone = connect_to_service( SERVICE_NETWORKING );
ERROR_PROPAGATE( pm_init());
if( ERROR_OCCURRED( arp_initialize())
|| ERROR_OCCURRED( REGISTER_ME( SERVICE_ARP, & phonehash ))){
pm_destroy();
return ERROR_CODE;
}
ERROR_PROPAGATE( arp_initialize());
ERROR_PROPAGATE( REGISTER_ME( SERVICE_ARP, & phonehash ));
 
async_manager();
 
pm_destroy();
return EOK;
}
 
/branches/network/uspace/srv/net/il/ip/ip_module.c
66,11 → 66,8
async_set_client_connection( client_connection );
ip_globals.networking_phone = connect_to_service( SERVICE_NETWORKING );
ERROR_PROPAGATE( pm_init());
if( ERROR_OCCURRED( ip_initialize())
|| ERROR_OCCURRED( REGISTER_ME( SERVICE_IP, & phonehash ))){
pm_destroy();
return ERROR_CODE;
}
ERROR_PROPAGATE( ip_initialize());
ERROR_PROPAGATE( REGISTER_ME( SERVICE_IP, & phonehash ));
 
async_manager();
 
/branches/network/uspace/srv/net/netif/netif.c
170,10 → 170,7
netif_globals.networking_phone = connect_to_service( SERVICE_NETWORKING );
device_map_initialize( & netif_globals.device_map );
ERROR_PROPAGATE( pm_init());
if( ERROR_OCCURRED( initialize())){
pm_destroy();
return ERROR_CODE;
}
ERROR_PROPAGATE( initialize());
 
async_manager();