Commit 2a2adbf9 authored by Arne Øslebø's avatar Arne Øslebø
Browse files

improved spinlock performance for returning results

git-svn-id: file:///home/svn/mapi/trunk@364 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent e882c308
...@@ -149,7 +149,7 @@ process_pkts(void *buf,unsigned len, dag_instance_t *i) ...@@ -149,7 +149,7 @@ process_pkts(void *buf,unsigned len, dag_instance_t *i)
if(!i->active) if(!i->active)
return len; return len;
mapid_lock(&i->mapidlib);
while (c + rlen < len && i->active) while (c + rlen < len && i->active)
{ {
char *p = buf; char *p = buf;
...@@ -171,7 +171,6 @@ process_pkts(void *buf,unsigned len, dag_instance_t *i) ...@@ -171,7 +171,6 @@ process_pkts(void *buf,unsigned len, dag_instance_t *i)
rlen = ntohs (rec->rlen); rlen = ntohs (rec->rlen);
i->hwinfo.pkts++; i->hwinfo.pkts++;
} }
mapid_unlock(&i->mapidlib);
return len - c; return len - c;
...@@ -189,7 +188,6 @@ process_pkts_offline(void *buf,unsigned len, dag_instance_t *i) ...@@ -189,7 +188,6 @@ process_pkts_offline(void *buf,unsigned len, dag_instance_t *i)
rec = (dag_record_t *) buf; rec = (dag_record_t *) buf;
rlen = ntohs (rec->rlen); rlen = ntohs (rec->rlen);
mapid_lock(&i->mapidlib);
while (c + rlen <= len && rlen!=0) while (c + rlen <= len && rlen!=0)
{ {
char *p = buf; char *p = buf;
...@@ -211,7 +209,6 @@ process_pkts_offline(void *buf,unsigned len, dag_instance_t *i) ...@@ -211,7 +209,6 @@ process_pkts_offline(void *buf,unsigned len, dag_instance_t *i)
rlen = ntohs (rec->rlen); rlen = ntohs (rec->rlen);
i->hwinfo.pkts++; i->hwinfo.pkts++;
} }
mapid_unlock(&i->mapidlib);
return len - c; return len - c;
......
...@@ -141,18 +141,6 @@ mapid_init(mapidlib_instance_t *i) ...@@ -141,18 +141,6 @@ mapid_init(mapidlib_instance_t *i)
return 0; return 0;
}; };
void mapid_lock(mapidlib_instance_t *i) {
// printf("Lock..\n");
pthread_spin_lock(i->shm_spinlock);
//printf("Locked\n");
}
void mapid_unlock(mapidlib_instance_t *i) {
//printf("Unlock..\n");
pthread_spin_unlock(i->shm_spinlock);
//printf("Unlocked\n");
}
//Function that can be used by MAPI functions for adding new functions to the flow //Function that can be used by MAPI functions for adding new functions to the flow
static int mapid_add_funct(mapidlib_instance_t *i, int fd, char *funct, ...) static int mapid_add_funct(mapidlib_instance_t *i, int fd, char *funct, ...)
{ {
...@@ -289,7 +277,7 @@ void mapid_destroy(mapidlib_instance_t *i) ...@@ -289,7 +277,7 @@ void mapid_destroy(mapidlib_instance_t *i)
struct mapidlibflow *f; struct mapidlibflow *f;
if (i!=NULL) { if (i!=NULL) {
mapid_lock(i); pthread_spin_lock(i->shm_spinlock);
// n=flist_head(i->flowlist); // n=flist_head(i->flowlist);
#ifdef WITH_PRIORITIES #ifdef WITH_PRIORITIES
int j = 0; int j = 0;
...@@ -315,7 +303,7 @@ void mapid_destroy(mapidlib_instance_t *i) ...@@ -315,7 +303,7 @@ void mapid_destroy(mapidlib_instance_t *i)
flist_destroy(i->flowlist,FLIST_FREE_DATA); flist_destroy(i->flowlist,FLIST_FREE_DATA);
#endif #endif
free(i->flowlist); free(i->flowlist);
mapid_unlock(i); pthread_spin_unlock(i->shm_spinlock);
} }
else if (libs_loaded>0) { else if (libs_loaded>0) {
...@@ -1022,6 +1010,7 @@ void mapid_process_pkt(mapidlib_instance_t *i, ...@@ -1022,6 +1010,7 @@ void mapid_process_pkt(mapidlib_instance_t *i,
if(funct->ref==1) if(funct->ref==1)
ret=funct->instance->ret; ret=funct->instance->ret;
else { else {
pthread_spin_lock(i->shm_spinlock);
#ifdef WITH_MODIFY_PKTS #ifdef WITH_MODIFY_PKTS
if(flow->modifies==1) if(flow->modifies==1)
ret=funct->instance->def->process(funct->instance,dev_pkt,flow->mod_pkt,&flow->mod_pkt_head); ret=funct->instance->def->process(funct->instance,dev_pkt,flow->mod_pkt,&flow->mod_pkt_head);
...@@ -1030,6 +1019,7 @@ void mapid_process_pkt(mapidlib_instance_t *i, ...@@ -1030,6 +1019,7 @@ void mapid_process_pkt(mapidlib_instance_t *i,
#else #else
ret=funct->instance->def->process(funct->instance,dev_pkt,link_pkt,pkt_head); ret=funct->instance->def->process(funct->instance,dev_pkt,link_pkt,pkt_head);
#endif #endif
pthread_spin_unlock(i->shm_spinlock);
#ifdef WITH_FUNCT_STATS #ifdef WITH_FUNCT_STATS
funct->instance->pkts++; funct->instance->pkts++;
if(ret) if(ret)
......
...@@ -91,8 +91,8 @@ int mapid_get_errno(mapidlib_instance_t *i,int fid); ...@@ -91,8 +91,8 @@ int mapid_get_errno(mapidlib_instance_t *i,int fid);
int mapid_get_devid(mapidlib_instance_t *i,int fd); int mapid_get_devid(mapidlib_instance_t *i,int fd);
int mapid_load_library(char *lib); int mapid_load_library(char *lib);
int mapid_get_flow_info(mapidlib_instance_t *i,int fd,mapi_flow_info_t *info); int mapid_get_flow_info(mapidlib_instance_t *i,int fd,mapi_flow_info_t *info);
void mapid_lock(mapidlib_instance_t *i); //void mapid_lock(mapidlib_instance_t *i);
void mapid_unlock(mapidlib_instance_t *i); //void mapid_unlock(mapidlib_instance_t *i);
mapid_funct_info_t* mapid_get_flow_functions(mapidlib_instance_t *i,int fd); mapid_funct_info_t* mapid_get_flow_functions(mapidlib_instance_t *i,int fd);
......
...@@ -147,8 +147,6 @@ process_pkts(void *buf,unsigned len, nic_instance_t *i,MAPI_UNUSED int devid, in ...@@ -147,8 +147,6 @@ process_pkts(void *buf,unsigned len, nic_instance_t *i,MAPI_UNUSED int devid, in
rec = (struct pcap_pkthdr *) buf; rec = (struct pcap_pkthdr *) buf;
rlen = rec->caplen+sizeof(struct pcap_pkthdr); rlen = rec->caplen+sizeof(struct pcap_pkthdr);
mapid_lock(&i->mapidlib);
while (c + rlen <= len) while (c + rlen <= len)
{ {
char *p = buf; char *p = buf;
...@@ -174,7 +172,6 @@ process_pkts(void *buf,unsigned len, nic_instance_t *i,MAPI_UNUSED int devid, in ...@@ -174,7 +172,6 @@ process_pkts(void *buf,unsigned len, nic_instance_t *i,MAPI_UNUSED int devid, in
rec = (struct pcap_pkthdr *) buf; rec = (struct pcap_pkthdr *) buf;
rlen = rec->caplen+sizeof(struct pcap_pkthdr); rlen = rec->caplen+sizeof(struct pcap_pkthdr);
} }
mapid_unlock(&i->mapidlib);
return len - c; return len - c;
...@@ -251,9 +248,7 @@ mapidrv_proc_loop (int devid) ...@@ -251,9 +248,7 @@ mapidrv_proc_loop (int devid)
i->hwinfo.pkts++; i->hwinfo.pkts++;
// Process packet // Process packet
mapid_lock(&i->mapidlib);
mapid_process_pkt(&i->mapidlib,packet,packet,&mhdr); mapid_process_pkt(&i->mapidlib,packet,packet,&mhdr);
mapid_unlock(&i->mapidlib);
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment