From: Jon M. <jon...@er...> - 2004-01-16 19:46:30
|
Good! I will use this. I was thinking about something else: The timer/signal item list in "handler.c" is a huge static area now, wasting memory and making the module look unecessary big. Since this function is not particularly time critical we could just as well allocate the individual items dynamically, when needed. It would be even better if it were possible to map the timer/signal handling directly to the Linux native dito, hence avoiding any items at all. Something that you could look into, in parallel with what I am doing ? I am working on the code again now, so expect things to move the next weeks. /Jon Guo, Min wrote: >Hi,jon > > With the below patch,the module can be inserted/removed correctly,but tipc_printf still has some problems. >Thanks >Guo Min > >Index: buf.c >=================================================================== >RCS file: /cvsroot/tipc/source/unstable/net/tipc/buf.c,v >retrieving revision 1.3 >diff -u -r1.3 buf.c >--- buf.c 4 Dec 2003 02:22:20 -0000 1.3 >+++ buf.c 16 Jan 2004 08:59:14 -0000 >@@ -85,16 +85,16 @@ > UB(crs)->pool = pool; > buf_set_next(crs,0); > if (pool){ >- spin_lock_bh(buf_lock); >+ spin_lock_bh(&buf_lock); > buf_set_next(crs,*pool); > *pool = crs; >- spin_unlock_bh(buf_lock); >+ spin_unlock_bh(&buf_lock); > } > } > if (pool){ >- spin_lock_bh(buf_lock); >+ spin_lock_bh(&buf_lock); > *pool = buf_next(crs); >- spin_unlock_bh(buf_lock); >+ spin_unlock_bh(&buf_lock); > } > buf_set_next(crs, 0); > return crs; >Index: dbg.c >=================================================================== >RCS file: /cvsroot/tipc/source/unstable/net/tipc/dbg.c,v >retrieving revision 1.1 >diff -u -r1.1 dbg.c >--- dbg.c 4 Dec 2003 02:22:20 -0000 1.1 >+++ dbg.c 16 Jan 2004 08:59:15 -0000 >@@ -135,6 +135,7 @@ > spin_lock_bh(&print_lock); > if (b->tee[0]) { > err("Init on TEE buffer\n"); >+ spin_unlock_bh(&print_lock); > return; > } > memset(raw, 0, sz); >@@ -161,7 +162,7 @@ > if (buf->tee[0]) { > targets[0] = buf->tee[0]; > targets[1] = buf->tee[1]; >- kfree(buf); >+ //kfree(buf); > } else { > targets[0] = buf; > targets[1] = 0; >@@ -171,16 +172,22 @@ > struct print_buf *b = targets[i++]; > if (!b) > continue; >- assert(!b->tee[0]); >+ if (!b->tee[0]) >+ { >+ spin_unlock_bh(&print_lock); >+ return; >+ } > if ((b->size - (b->crs - b->buf)) < MAX_STRING) > b->crs = b->buf; > FORMAT(b->crs, len, fmt); > if (((b->crs + len) - b->buf) > b->size) { > assert(!"Overstepped print/log buffer!!!\n"); > } >- if (b == CONS) >+ if ((b == CONS) && ( b->crs)) > printk(b->crs); >- b->crs += len; >+ if (b->crs) >+ b->crs += len; >+ > } > spin_unlock_bh(&print_lock); > } >@@ -218,7 +225,7 @@ > if (buf->tee[0]) { > targets[0] = buf->tee[0]; > targets[1] = buf->tee[1]; >- kfree(buf); >+ //kfree(buf); > } else { > targets[0] = buf; > targets[1] = 0; > > >Index: handler.c >=================================================================== >RCS file: /cvsroot/tipc/source/unstable/net/tipc/handler.c,v >retrieving revision 1.4 >diff -u -r1.4 handler.c >--- handler.c 4 Dec 2003 02:22:20 -0000 1.4 >+++ handler.c 16 Jan 2004 08:59:16 -0000 >@@ -187,6 +187,7 @@ > struct queue_item *item; > > spin_lock_bh(&qitem_lock); >+ > item = (struct queue_item *) __get_queue_item(); > item->handler = routine; > item->data = eventInfo; >@@ -197,8 +198,10 @@ > signal_queue_head = item; > } > signal_queue_tail = item; >+ > spin_unlock_bh(&qitem_lock); >- tasklet_schedule(&tipc_tasklet); >+ >+ //tasklet_schedule(&tipc_tasklet); > return 0; > } > >@@ -280,6 +283,8 @@ > } > } > spin_unlock_bh(&qitem_lock); >+ >+ buf_stop(); > } > > uint >Index: link.c >=================================================================== >RCS file: /cvsroot/tipc/source/unstable/net/tipc/link.c,v >retrieving revision 1.2 >diff -u -r1.2 link.c >--- link.c 11 Dec 2003 19:44:47 -0000 1.2 >+++ link.c 16 Jan 2004 08:59:18 -0000 >@@ -1406,19 +1406,19 @@ > head = link_insert_deferred_queue(this,head); > if (likely(msg_is_dest(msg,tipc_own_addr))){ > if (likely(msg_isdata(msg))) { >- spin_unlock_bh(this->owner->lock); >+ spin_unlock_bh(&this->owner->lock); > port_recv_msg(buf); > continue; > } > link_recv_non_data_msg(this, buf); > continue; > } >- spin_unlock_bh(this->owner->lock); >+ spin_unlock_bh(&this->owner->lock); > net_route_msg(buf); > continue; > } > link_handle_non_seq_msg(this, buf); >- spin_unlock_bh(this->owner->lock); >+ spin_unlock_bh(&this->owner->lock); > continue; > } > >@@ -1431,7 +1431,7 @@ > else > buf_discard(buf); > >- spin_unlock_bh(this->owner->lock); >+ spin_unlock_bh(&this->owner->lock); > continue; > } > } >Index: link.h >=================================================================== >RCS file: /cvsroot/tipc/source/unstable/net/tipc/link.h,v >retrieving revision 1.1 >diff -u -r1.1 link.h >--- link.h 4 Dec 2003 02:22:20 -0000 1.1 >+++ link.h 16 Jan 2004 08:59:19 -0000 >@@ -270,11 +270,11 @@ > struct node *node = node_find(addr); > if (likely(node)){ > struct link* l; >- spin_lock_bh(node->lock); >+ spin_lock_bh(&node->lock); > l = node->links[bearer_id]; > if (likely(l)) > return l; >- spin_unlock_bh(node->lock); >+ spin_unlock_bh(&node->lock); > } > return 0; > } >Index: media.c >=================================================================== >RCS file: /cvsroot/tipc/source/unstable/net/tipc/media.c,v >retrieving revision 1.1 >diff -u -r1.1 media.c >--- media.c 4 Dec 2003 02:22:20 -0000 1.1 >+++ media.c 16 Jan 2004 08:59:19 -0000 >@@ -376,16 +376,18 @@ > struct media *media = &media_list[0]; > struct print_buf buf; > printbuf_init(&buf,raw,sz); > while (media->active) { > uint i; > for (i = 0; i < MAX_BEARERS; i++) { > struct bearer *b = &bearers[i]; > if (b->active && (b->media == media)) { >- tipc_printf(&buf, "%s\n", b->publ.name); >+ // tipc_printf(&buf, "%s\n", b->publ.name); > } > } > media++; > } >+ > return TIPC_OK; > } > >Index: port.c >=================================================================== >RCS file: /cvsroot/tipc/source/unstable/net/tipc/port.c,v >retrieving revision 1.1 >diff -u -r1.1 port.c >--- port.c 4 Dec 2003 02:22:20 -0000 1.1 >+++ port.c 16 Jan 2004 08:59:20 -0000 >@@ -751,13 +751,13 @@ > port_dispatcher_sigh(buf); > return 1; > } >- spin_lock_bh(queue_lock); >+ spin_lock_bh(&queue_lock); > if (msg_queue_head) > buf_set_next(msg_queue_tail, buf); > else > msg_queue_head = buf; > msg_queue_tail = buf; >- spin_lock_bh(queue_lock); >+ spin_lock_bh(&queue_lock); > k_signal((Handler)port_dispatcher_sigh, 0); > return 1; > } >@@ -1272,10 +1272,10 @@ > { > struct port* p = ports; > struct sk_buff* b; >- spin_lock_bh(queue_lock); >+ spin_lock_bh(&queue_lock); > b = msg_queue_head; > msg_queue_head = 0; >- spin_unlock_bh(queue_lock); >+ spin_unlock_bh(&queue_lock); > while (b) { > struct sk_buff *next = buf_next(b); > buf_discard(b); >Index: reg.c >=================================================================== >RCS file: /cvsroot/tipc/source/unstable/net/tipc/reg.c,v >retrieving revision 1.1 >diff -u -r1.1 reg.c >--- reg.c 4 Dec 2003 02:22:20 -0000 1.1 >+++ reg.c 16 Jan 2004 08:59:21 -0000 >@@ -92,7 +92,7 @@ > uint sz = 1 << 4; > while (sz < requested_size) > sz <<= 1; >- write_lock(ref_lock); >+ write_lock(&ref_lock); > table = (struct reference *) k_malloc(sizeof (struct reference) * sz); > table[0].object = 0; > table[0].data.reference = ~0u; >@@ -106,7 +106,7 @@ > ref_table.entries = table; > ref_table.first_free = 1; > ref_table.last_free = sz - 1; >- write_unlock(ref_lock); >+ write_unlock(&ref_lock); > } > > uint >@@ -136,7 +136,7 @@ > { > struct reference *entry; > uint index_mask,index; >- write_lock(ref_lock); >+ write_lock(&ref_lock); > index_mask = ref_table.index_mask; > index = ref_nb & index_mask; > entry = &(ref_table.entries[index]); >@@ -155,7 +155,7 @@ > } > ref_table.last_free = index; > entry->data.next_plus_upper = (ref_nb & ~index_mask) + index_mask + 1; >- write_unlock(ref_lock); >+ write_unlock(&ref_lock); > } > > >@@ -182,7 +182,7 @@ > return TIPC_FAILURE; > if (p->reg_ref == 0) > return TIPC_OK; >- spin_lock_bh(reg_lock); >+ spin_lock_bh(®_lock); > user = &users[ref]; > p->reg_ref = ref; > p->prev = 0; >@@ -190,7 +190,7 @@ > if (p->next) > p->next->prev = p; > user->ports = p; >- spin_unlock_bh(reg_lock); >+ spin_unlock_bh(®_lock); > return TIPC_OK; > } > >@@ -203,7 +203,7 @@ > return TIPC_FAILURE; > if (p->reg_ref == 0) > return TIPC_OK; >- spin_lock_bh(reg_lock); >+ spin_lock_bh(®_lock); > user = &users[p->reg_ref]; > if (p->prev) > p->prev->next = p->next; >@@ -211,7 +211,7 @@ > user->ports = p->next; > if (p->next) > p->next->prev = p->prev; >- spin_unlock_bh(reg_lock); >+ spin_unlock_bh(®_lock); > return TIPC_OK; > } > >@@ -225,7 +225,7 @@ > return TIPC_FAILURE; > if (s->reg.ref == 0) > return TIPC_OK; >- spin_lock_bh(reg_lock); >+ spin_lock_bh(®_lock); > user = &users[s->reg.ref]; > s->reg.ref = ref; > s->reg.prev = 0; >@@ -233,7 +233,7 @@ > if (s->reg.next) > s->reg.next->reg.prev = s; > user->subs = s; >- spin_unlock_bh(reg_lock); >+ spin_unlock_bh(®_lock); > return TIPC_OK; > } > >@@ -246,7 +246,7 @@ > return TIPC_FAILURE; > if (s->reg.ref == 0) > return TIPC_OK; >- spin_lock_bh(reg_lock); >+ spin_lock_bh(®_lock); > user = &users[s->reg.ref]; > if (s->reg.prev) > s->reg.prev->reg.next = s->reg.next; >@@ -254,21 +254,21 @@ > user->subs = s->reg.next; > if (s->next) > s->reg.next->reg.prev = s->reg.prev; >- spin_unlock_bh(reg_lock); >+ spin_unlock_bh(®_lock); > return TIPC_OK; > } > > static void reg_init(void) > { > uint i = 1; >- spin_lock_bh(reg_lock); >+ spin_lock_bh(®_lock); > users = (struct tipc_user*)k_malloc(sizeof(struct tipc_user)); > memset(users, 0, sizeof (users)); > for (i = 1; i <= MAX_USERID; i++) { > users[i].next = i - 1; > } > next_free_user = MAX_USERID; >- spin_lock_bh(reg_lock); >+ spin_unlock_bh(®_lock); > } > > >@@ -290,10 +290,10 @@ > { > struct tipc_user *user = (struct tipc_user *) u; > tipc_started_event cb; >- spin_lock_bh(reg_lock); >+ spin_lock_bh(®_lock); > cb = user->callback; > user->callback = 0; >- spin_unlock_bh(reg_lock); >+ spin_unlock_bh(®_lock); > if (!cb) > return; > user->callback(user->usr_handle); >@@ -343,25 +343,41 @@ > struct name_subscr* s = 0; > struct user_port* p = 0; > struct tipc_user *user; >- spin_lock_bh(reg_lock); >+ spin_lock_bh(®_lock); > user = &users[userid]; >- if (!user->next){ >+ if (NULL == user->next){ > s = user->subs; > p = user->ports; > user->subs = 0; > user->ports = 0; > user->next = next_free_user; >- spin_unlock_bh(reg_lock); >- } >- while (s) { >- tipc_unsubscribe(s->publ.s.ref); >+ } >+ spin_unlock_bh(®_lock); >+ while (user->subs) { >+ tipc_unsubscribe(user->subs->publ.s.ref); > } > while (user->ports) { >- tipc_deleteport(p->ref); >+ tipc_deleteport(user->ports->ref); > } >+ > } > > >Index: socket.c >=================================================================== >RCS file: /cvsroot/tipc/source/unstable/net/tipc/socket.c,v >retrieving revision 1.2 >diff -u -r1.2 socket.c >--- socket.c 4 Dec 2003 03:02:57 -0000 1.2 >+++ socket.c 16 Jan 2004 08:59:21 -0000 >@@ -277,9 +277,9 @@ > struct sk_buff *buf; > if (!tsk) > return 0; >- spin_lock_bh(tsk); >+ sock_lock(tsk); > if (!sock->sk) { >- spin_unlock_bh(tsk); >+ sock_unlock(tsk); > return 0; > } > sock->sk = NULL; >@@ -304,7 +304,7 @@ > } > > res = tipc_deleteport(tsk->p->ref); >- spin_unlock_bh(tsk); >+ sock_unlock(tsk); > kfree(tsk); > reset_protinfo(sk); > sk_free(sk); >@@ -323,7 +323,7 @@ > return -EFAULT; > if (i_sock_lock(tsk)) > return -ERESTARTSYS; >- if (addr->addrtype != TIPC_ADDR_NAMESEQ) >+ if (addr->addrtype == TIPC_ADDR_NAMESEQ) > res = tipc_publish_nameseq(tsk->p->ref, > tsk->bind_scope, > &addr->addr.nameseq); >@@ -333,7 +333,7 @@ > tsk->bind_scope, > &addr->addr.nameseq); > } >- spin_unlock_bh(tsk); >+ sock_unlock(tsk); > return res ? -EINVAL : 0; > } > >@@ -350,7 +350,7 @@ > res = tipc_connect2port(tsk->p->ref, &addr->addr.id); > if (res == TIPC_OK) > sk->state = SS_CONNECTED; >- spin_unlock_bh(tsk); >+ sock_unlock(tsk); > return res ? -EFAULT : 0; > } > >@@ -407,6 +407,7 @@ > tipc_ref_t new_ref = new_tsk->p->ref; > id.ref = msg_origport(buf_msg(buf)); > id.node = msg_orignode(buf_msg(buf)); >+ user_lock(&tsk->p->lock); > tipc_connect2port(new_ref, &id); > tipc_setportimportance(new_ref,msg_importance(msg)); > tsk->queue_head = buf_next(buf); >@@ -421,7 +422,7 @@ > user_unlock(&tsk->p->lock); > } > exit: >- spin_unlock_bh(tsk); >+ sock_unlock(tsk); > return res; > } > >@@ -448,7 +449,7 @@ > } else > res = -EFAULT; > *uaddr_len = sizeof (*addr); >- spin_unlock_bh(tsk); >+ sock_unlock(tsk); > return res; > } > >@@ -462,7 +463,7 @@ > return -ERESTARTSYS; > sock->state = SS_UNCONNECTED; > res = tipc_disconnect(tsk->p->ref); >- spin_unlock_bh(tsk); >+ sock_unlock(tsk); > return res; > } > >@@ -492,7 +493,7 @@ > for (; section < scount; size += sseq[section].size, section++) { > } > if (unlikely(size > TIPC_MAX_DATA_SIZE)) { >- spin_unlock_bh(tsk); >+ sock_unlock(tsk); > return -EINVAL; > } > >@@ -509,7 +510,7 @@ > > if (unlikely(tsk->pollmask & CONNECTION_ABORTED)) { > user_unlock(&tsk->p->lock); >- spin_unlock_bh(tsk); >+ sock_unlock(tsk); > buf_discard(buf); > return -ECONNABORTED; > } >@@ -534,7 +535,7 @@ > > if (likely(res == TIPC_OK)) { > exit: >- spin_unlock_bh(tsk); >+ sock_unlock(tsk); > return size; > } > >@@ -560,7 +561,7 @@ > } > error_locked: > error_non_locked: >- spin_unlock_bh(tsk); >+ sock_unlock(tsk); > buf_discard(buf); > return res; > } >@@ -618,13 +619,13 @@ > if (unlikely > (wait_event_interruptible(tsk->waitqueue, tsk->queue_head))) { > return -ERESTARTSYS; >- spin_unlock_bh(tsk); >+ sock_unlock(tsk); > } > buf = tsk->queue_head; > > if (unlikely(tsk->pollmask & MSG_ERROR)) { > user_unlock(&tsk->p->lock); >- spin_unlock_bh(tsk); >+ sock_unlock(tsk); > return -1; > } > >@@ -689,7 +690,7 @@ > } > > recvmsg_exit: >- spin_unlock_bh(tsk); >+ sock_unlock(tsk); > return res; > } > >@@ -811,7 +812,7 @@ > } > } > user_unlock(&tsk->p->lock); >- spin_unlock_bh(tsk); >+ sock_unlock(tsk); > return res; > } > >@@ -881,7 +882,7 @@ > } > } > user_unlock(&tsk->p->lock); >- spin_unlock_bh(tsk); >+ sock_unlock(tsk); > return !!res; > } > >@@ -926,12 +927,12 @@ > s->usr_next = tsk->sub_list; > tsk->sub_list = s; > user_unlock(&tsk->p->lock); >- spin_unlock_bh(tsk); >+ sock_unlock(tsk); > put_user(s->s.ref, &((struct tipc_subscr *) arg)->ref); > return 0; > } > user_unlock(&tsk->p->lock); >- spin_unlock_bh(tsk); >+ sock_unlock(tsk); > return -EINVAL; > > } >@@ -964,7 +965,7 @@ > } > user_unlock(&tsk->p->lock); > } >- spin_unlock_bh(tsk); >+ sock_unlock(tsk); > return res; > } > >@@ -1013,7 +1014,7 @@ > tsk->pollmask |= tsk->ev_head->ev.event; > > user_unlock(&tsk->p->lock); >- spin_unlock_bh(tsk); >+ sock_unlock(tsk); > return res; > > } >Index: tipc_buf.h >=================================================================== >RCS file: /cvsroot/tipc/source/unstable/net/tipc/tipc_buf.h,v >retrieving revision 1.3 >diff -u -r1.3 tipc_buf.h >--- tipc_buf.h 4 Dec 2003 02:22:20 -0000 1.3 >+++ tipc_buf.h 16 Jan 2004 08:59:22 -0000 >@@ -169,12 +169,12 @@ > static inline void buf_discard(struct sk_buff *skb) > { > if (likely(UB(skb)->pool)) { >- spin_lock_bh(buf_lock); >+ spin_lock_bh(&buf_lock); > skb->nh.raw = skb->data = UB(skb)->data = > skb->head + BUF_HEADROOM; > buf_set_next(skb, *(UB(skb)->pool)); > *(UB(skb)->pool) = skb; >- spin_unlock_bh(buf_lock); >+ spin_unlock_bh(&buf_lock); > return; > } > kfree_skb(skb); >@@ -184,17 +184,17 @@ > { > struct sk_buff *skb; > if (likely(size <= SMALL_POOL_MSG_SIZE)) { >- spin_lock_bh(buf_lock); >+ spin_lock_bh(&buf_lock); > skb = small_pool; > if (likely(skb)) { > small_pool = buf_next(skb); >- spin_unlock_bh(buf_lock); >+ spin_unlock_bh(&buf_lock); > return skb; > } >- spin_unlock_bh(buf_lock); >+ spin_unlock_bh(&buf_lock); > return acquire_bufs(SMALL_POOL_MSG_SIZE, 40, &small_pool); > } else if (size <= MEDIUM_POOL_MSG_SIZE) { >- spin_lock_bh(buf_lock); >+ spin_lock_bh(&buf_lock); > skb = big_pool; > if (skb) { > big_pool = buf_next(skb); > > |