From: Rainer Toebbicke Date: Mon, 3 Mar 2003 15:53:28 +0000 (+0000) Subject: rx-thread-id-startup-20030303 X-Git-Tag: openafs-devel-1_3_50~351 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=45a4d9cb08d92c10332bda071afb35461d5a4cc3;p=packages%2Fo%2Fopenafs.git rx-thread-id-startup-20030303 FIXES 1304 avoid using rxi_availProcs to allocate thread ids as it may decrement from under us --- diff --git a/src/rx/rx.c b/src/rx/rx.c index 0be9f4adb..45ac9cbed 100644 --- a/src/rx/rx.c +++ b/src/rx/rx.c @@ -1429,8 +1429,8 @@ struct rx_call *rx_GetCall(int tno, struct rx_service *cur_service, osi_socket * if (!QuotaOK(service)) { continue; } - if (!tno || !tcall->queue_item_header.next) { - /* If we're thread 0, then we'll just use + if (tno==rxi_fcfs_thread_num || !tcall->queue_item_header.next ) { + /* If we're the fcfs thread , then we'll just use * this call. If we haven't been able to find an optimal * choice, and we're at the end of the list, then use a * 2d choice if one has been identified. Otherwise... */ @@ -1578,8 +1578,8 @@ struct rx_call *rx_GetCall(int tno, struct rx_service *cur_service, osi_socket * for (queue_Scan(&rx_incomingCallQueue, tcall, ncall, rx_call)) { service = tcall->conn->service; if (QuotaOK(service)) { - if (!tno || !tcall->queue_item_header.next ) { - /* If we're thread 0, then we'll just use + if (tno==rxi_fcfs_thread_num || !tcall->queue_item_header.next ) { + /* If we're the fcfs thread, then we'll just use * this call. If we haven't been able to find an optimal * choice, and we're at the end of the list, then use a * 2d choice if one has been identified. Otherwise... */ diff --git a/src/rx/rx_globals.h b/src/rx/rx_globals.h index 2c2b425de..870e36c6b 100644 --- a/src/rx/rx_globals.h +++ b/src/rx/rx_globals.h @@ -316,10 +316,13 @@ EXT int rxi_callAbortDelay INIT(3000); */ #if defined(AFS_PTHREAD_ENV) +EXT int rxi_fcfs_thread_num INIT(0); EXT pthread_key_t rx_thread_id_key; /* keep track of pthread numbers - protected by rx_stats_mutex, except in rx_Init() before mutex exists! */ EXT int rxi_pthread_hinum INIT(0); +#else +#define rxi_fcfs_thread_num (0) #endif #if defined(RX_ENABLE_LOCKS) diff --git a/src/rx/rx_pthread.c b/src/rx/rx_pthread.c index 3820d2ee4..dbf6b9bdd 100644 --- a/src/rx/rx_pthread.c +++ b/src/rx/rx_pthread.c @@ -130,9 +130,6 @@ void rxi_StartServerProc(void (*proc)(void), int stacksize) printf("Unable to Create Rx server thread\n"); exit(1); } - MUTEX_ENTER(&rx_stats_mutex); - ++rxi_pthread_hinum; - MUTEX_EXIT(&rx_stats_mutex); AFS_SIGSET_RESTORE(); } @@ -277,7 +274,21 @@ void rx_ServerProc(void) rxi_dataQuota += rx_initSendWindow; /* Reserve some pkts for hard times */ /* threadID is used for making decisions in GetCall. Get it by bumping * number of threads handling incoming calls */ - threadID = rxi_availProcs++; + /* Unique thread ID: used for scheduling purposes *and* as index into + the host hold table (fileserver). + The previously used rxi_availProcs is unsuitable as it + will already go up and down as packets arrive while the server + threads are still initialising! The recently introduced + rxi_pthread_hinum does not necessarily lead to a server + thread with id 0, which is not allowed to hop through the + incoming call queue. + So either introduce yet another counter or flag the FCFS + thread... chose the latter. + */ + threadID = ++rxi_pthread_hinum; + if (rxi_fcfs_thread_num==0 && rxi_fcfs_thread_num!=threadID) + rxi_fcfs_thread_num=threadID; + ++rxi_availProcs; MUTEX_EXIT(&rx_stats_mutex); while(1) {