Diff for /src/sys/kern/lwkt_token.c between versions 1.1 and 1.2

version 1.1, 2004/02/09 21:13:18 version 1.2, 2004/02/10 07:34:42
Line 89  SYSCTL_INT(_lwkt, OID_AUTO, token_debug, Line 89  SYSCTL_INT(_lwkt, OID_AUTO, token_debug,
   
 typedef struct lwkt_gettoken_req {  typedef struct lwkt_gettoken_req {
     lwkt_token_t tok;      lwkt_token_t tok;
    int                cpu;    globaldata_t cpu;
 } lwkt_gettoken_req;  } lwkt_gettoken_req;
   
 /*  /*
Line 105  typedef struct lwkt_gettoken_req { Line 105  typedef struct lwkt_gettoken_req {
  * a token, but do we really only need to disable IPIs ?   * a token, but do we really only need to disable IPIs ?
  *   *
  * YYY certain tokens could be made to act like mutexes when performance   * YYY certain tokens could be made to act like mutexes when performance
 * would be better (e.g. t_cpu == -1).  This is not yet implemented. * would be better (e.g. t_cpu == NULL).  This is not yet implemented.
  *   *
  * YYY the tokens replace 4.x's simplelocks for the most part, but this   * YYY the tokens replace 4.x's simplelocks for the most part, but this
  * means that 4.x does not expect a switch so for now we cannot switch   * means that 4.x does not expect a switch so for now we cannot switch
Line 125  void Line 125  void
 lwkt_gettoken_remote(void *arg)  lwkt_gettoken_remote(void *arg)
 {  {
     lwkt_gettoken_req *req = arg;      lwkt_gettoken_req *req = arg;
    if (req->tok->t_cpu == mycpu->gd_cpuid) {    if (req->tok->t_cpu == mycpu) {
 #ifdef INVARIANTS  #ifdef INVARIANTS
         if (token_debug)          if (token_debug)
            printf("GT(%d,%d) ", req->tok->t_cpu, req->cpu);            printf("GT(%d,%d) ", req->tok->t_cpu->gd_cpuid, req->cpu->gd_cpuid);
 #endif  #endif
         req->tok->t_cpu = req->cpu;          req->tok->t_cpu = req->cpu;
         req->tok->t_reqcpu = req->cpu;  /* YYY leave owned by target cpu */          req->tok->t_reqcpu = req->cpu;  /* YYY leave owned by target cpu */
Line 160  lwkt_gettoken(lwkt_token_t tok) Line 160  lwkt_gettoken(lwkt_token_t tok)
     }      }
 #endif  #endif
 #ifdef SMP  #ifdef SMP
    while (tok->t_cpu != mycpu->gd_cpuid) {    while (tok->t_cpu != mycpu) {
         struct lwkt_gettoken_req req;          struct lwkt_gettoken_req req;
         int seq;          int seq;
        int dcpu;        globaldata_t dcpu;
   
        req.cpu = mycpu->gd_cpuid;        req.cpu = mycpu;
         req.tok = tok;          req.tok = tok;
        dcpu = (volatile int)tok->t_cpu;        dcpu = tok->t_cpu;
        KKASSERT(dcpu >= 0 && dcpu < ncpus); 
 #ifdef INVARIANTS  #ifdef INVARIANTS
         if (token_debug)          if (token_debug)
            printf("REQT%d ", dcpu);            printf("REQT%d ", dcpu->gd_cpuid);
 #endif  #endif
        seq = lwkt_send_ipiq(dcpu, lwkt_gettoken_remote, &req);        seq = lwkt_send_ipiq(dcpu->gd_cpuid, lwkt_gettoken_remote, &req);
        lwkt_wait_ipiq(dcpu, seq);        lwkt_wait_ipiq(dcpu->gd_cpuid, seq);
 #ifdef INVARIANTS  #ifdef INVARIANTS
         if (token_debug)          if (token_debug)
            printf("REQR%d ", tok->t_cpu);            printf("REQR%d ", tok->t_cpu->gd_cpuid);
 #endif  #endif
     }      }
 #endif  #endif
Line 197  lwkt_trytoken(lwkt_token_t tok) Line 196  lwkt_trytoken(lwkt_token_t tok)
 {  {
     crit_enter();      crit_enter();
 #ifdef SMP  #ifdef SMP
    if (tok->t_cpu != mycpu->gd_cpuid) {    if (tok->t_cpu != mycpu) {
         crit_exit();          crit_exit();
         return(0);          return(0);
     }       } 
Line 226  lwkt_reltoken(lwkt_token_t tok) Line 225  lwkt_reltoken(lwkt_token_t tok)
 {  {
     int gen;      int gen;
   
    if (tok->t_cpu == mycpu->gd_cpuid) {    if (tok->t_cpu == mycpu) {
         tok->t_cpu = tok->t_reqcpu;          tok->t_cpu = tok->t_reqcpu;
     }      }
     gen = tok->t_gen;      gen = tok->t_gen;
Line 246  lwkt_reltoken(lwkt_token_t tok) Line 245  lwkt_reltoken(lwkt_token_t tok)
 int  int
 lwkt_gentoken(lwkt_token_t tok, int *gen)  lwkt_gentoken(lwkt_token_t tok, int *gen)
 {  {
    if (tok->t_cpu == mycpu->gd_cpuid && tok->t_gen == *gen)    if (tok->t_cpu == mycpu && tok->t_gen == *gen)
         return(0);          return(0);
     *gen = lwkt_regettoken(tok);      *gen = lwkt_regettoken(tok);
     return(-1);      return(-1);
Line 262  int Line 261  int
 lwkt_regettoken(lwkt_token_t tok)  lwkt_regettoken(lwkt_token_t tok)
 {  {
     /* assert we are in a critical section */      /* assert we are in a critical section */
    if (tok->t_cpu != mycpu->gd_cpuid) {    if (tok->t_cpu != mycpu) {
 #ifdef SMP  #ifdef SMP
        while (tok->t_cpu != mycpu->gd_cpuid) {        while (tok->t_cpu != mycpu) {
             struct lwkt_gettoken_req req;              struct lwkt_gettoken_req req;
             int seq;              int seq;
            int dcpu;            globaldata_t dcpu;
   
            req.cpu = mycpu->gd_cpuid;            req.cpu = mycpu;
             req.tok = tok;              req.tok = tok;
            dcpu = (volatile int)tok->t_cpu;            dcpu = tok->t_cpu;
            KKASSERT(dcpu >= 0 && dcpu < ncpus); 
 #ifdef INVARIANTS  #ifdef INVARIANTS
             if (token_debug)              if (token_debug)
                printf("REQT%d ", dcpu);                printf("REQT%d ", dcpu->gd_cpuid);
 #endif  #endif
            seq = lwkt_send_ipiq(dcpu, lwkt_gettoken_remote, &req);            seq = lwkt_send_ipiq(dcpu->gd_cpuid, lwkt_gettoken_remote, &req);
            lwkt_wait_ipiq(dcpu, seq);            lwkt_wait_ipiq(dcpu->gd_cpuid, seq);
 #ifdef INVARIATNS  #ifdef INVARIATNS
             if (token_debug)              if (token_debug)
                printf("REQR%d ", tok->t_cpu);                printf("REQR%d ", tok->t_cpu->gd_cpuid);
 #endif  #endif
         }          }
 #endif  #endif
Line 296  lwkt_inittoken(lwkt_token_t tok) Line 294  lwkt_inittoken(lwkt_token_t tok)
     /*      /*
      * Zero structure and set cpu owner and reqcpu to cpu 0.       * Zero structure and set cpu owner and reqcpu to cpu 0.
      */       */
    bzero(tok, sizeof(*tok));    tok->t_cpu = tok->t_reqcpu = mycpu;
     tok->t_gen = 0;
 }  }
   

Removed from v.1.1  
changed lines
  Added in v.1.2