diff options
author | in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2003-09-26 13:09:03 +0800 |
---|---|---|
committer | in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2003-09-26 13:09:03 +0800 |
commit | 5231e61010f2dbf7b20a285e553247d7c255444c (patch) | |
tree | 2d6839399951bf3fbe0cde0a977eb25e0b322115 /util/shmctl.c | |
parent | ab58838e7a36240fe3f400ad6e44436b8c9c1042 (diff) | |
download | pttbbs-5231e61010f2dbf7b20a285e553247d7c255444c.tar pttbbs-5231e61010f2dbf7b20a285e553247d7c255444c.tar.gz pttbbs-5231e61010f2dbf7b20a285e553247d7c255444c.tar.bz2 pttbbs-5231e61010f2dbf7b20a285e553247d7c255444c.tar.lz pttbbs-5231e61010f2dbf7b20a285e553247d7c255444c.tar.xz pttbbs-5231e61010f2dbf7b20a285e553247d7c255444c.tar.zst pttbbs-5231e61010f2dbf7b20a285e553247d7c255444c.zip |
reduce sort times in utmpsortd
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@1199 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'util/shmctl.c')
-rw-r--r-- | util/shmctl.c | 71 |
1 files changed, 44 insertions, 27 deletions
diff --git a/util/shmctl.c b/util/shmctl.c index 750f0763..92a220e4 100644 --- a/util/shmctl.c +++ b/util/shmctl.c @@ -205,7 +205,7 @@ cmputmpuid(const void *i, const void *j) return (*((userinfo_t **) i))->uid - (*((userinfo_t **) j))->uid; } -inline void utmpsort(void) +inline void utmpsort(int sortall) { userinfo_t *uentp; int count, i, ns; @@ -233,39 +233,49 @@ inline void utmpsort(void) qsort(SHM->sorted[ns][0], count, sizeof(userinfo_t *), cmputmpuserid); for (i = 0; i < count; ++i) ((userinfo_t *) SHM->sorted[ns][0][i])->idoffset = i; - memcpy(SHM->sorted[ns][1], SHM->sorted[ns][0], sizeof(userinfo_t *) * count); - memcpy(SHM->sorted[ns][2], SHM->sorted[ns][0], sizeof(userinfo_t *) * count); - memcpy(SHM->sorted[ns][3], SHM->sorted[ns][0], sizeof(userinfo_t *) * count); - memcpy(SHM->sorted[ns][4], SHM->sorted[ns][0], sizeof(userinfo_t *) * count); - memcpy(SHM->sorted[ns][5], SHM->sorted[ns][0], sizeof(userinfo_t *) * count); - memcpy(SHM->sorted[ns][6], SHM->sorted[ns][0], sizeof(userinfo_t *) * count); - memcpy(SHM->sorted[ns][7], SHM->sorted[ns][0], sizeof(userinfo_t *) * count); - qsort(SHM->sorted[ns][1], count, sizeof(userinfo_t *), cmputmpmode); - qsort(SHM->sorted[ns][2], count, sizeof(userinfo_t *), cmputmpidle); - qsort(SHM->sorted[ns][3], count, sizeof(userinfo_t *), cmputmpfrom); - qsort(SHM->sorted[ns][4], count, sizeof(userinfo_t *), cmputmpfive); - qsort(SHM->sorted[ns][5], count, sizeof(userinfo_t *), cmputmpchc); + memcpy(SHM->sorted[ns][6], + SHM->sorted[ns][0], sizeof(userinfo_t *) * count); + memcpy(SHM->sorted[ns][7], + SHM->sorted[ns][0], sizeof(userinfo_t *) * count); qsort(SHM->sorted[ns][6], count, sizeof(userinfo_t *), cmputmpuid); qsort(SHM->sorted[ns][7], count, sizeof(userinfo_t *), cmputmppid); + if( sortall ){ + memcpy(SHM->sorted[ns][1], + SHM->sorted[ns][0], sizeof(userinfo_t *) * count); + memcpy(SHM->sorted[ns][2], + SHM->sorted[ns][0], sizeof(userinfo_t *) * count); + memcpy(SHM->sorted[ns][3], + SHM->sorted[ns][0], sizeof(userinfo_t *) * count); + memcpy(SHM->sorted[ns][4], + SHM->sorted[ns][0], sizeof(userinfo_t *) * count); + memcpy(SHM->sorted[ns][5], + SHM->sorted[ns][0], sizeof(userinfo_t *) * count); + qsort(SHM->sorted[ns][1], count, sizeof(userinfo_t *), cmputmpmode); + qsort(SHM->sorted[ns][2], count, sizeof(userinfo_t *), cmputmpidle); + qsort(SHM->sorted[ns][3], count, sizeof(userinfo_t *), cmputmpfrom); + qsort(SHM->sorted[ns][4], count, sizeof(userinfo_t *), cmputmpfive); + qsort(SHM->sorted[ns][5], count, sizeof(userinfo_t *), cmputmpchc); + memset(nusers, 0, sizeof(nusers)); + for (i = 0; i < count; ++i) { + uentp = SHM->sorted[ns][0][i]; + if (uentp && uentp->pid && + 0 < uentp->brc_id && uentp->brc_id < MAX_BOARD) + ++nusers[uentp->brc_id - 1]; + } + for (i = 0; i < SHM->Bnumber; ++i) + if (SHM->bcache[i].brdname[0] != 0) + SHM->bcache[i].nuser = nusers[i]; + } + SHM->currsorted = ns; SHM->UTMPbusystate = 0; - - memset(nusers, 0, sizeof(nusers)); - for (i = 0; i < count; ++i) { - uentp = SHM->sorted[ns][0][i]; - if (uentp && uentp->pid && - 0 < uentp->brc_id && uentp->brc_id < MAX_BOARD) - ++nusers[uentp->brc_id - 1]; - } - for (i = 0; i < SHM->Bnumber; ++i) - if (SHM->bcache[i].brdname[0] != 0) - SHM->bcache[i].nuser = nusers[i]; } int utmpsortd(int argc, char **argv) { pid_t pid; int interval; // sleep interval in microsecond(1/10**6) + int sortall, counter = 0; if( fork() > 0 ){ puts("sortutmpd daemonized..."); @@ -273,8 +283,9 @@ int utmpsortd(int argc, char **argv) } setproctitle("shmctl utmpsortd"); - if( argc != 2 || (interval = atoi(argv[1])) < 500000 ) + if( argc < 2 || (interval = atoi(argv[1])) < 500000 ) interval = 1000000; // default to 1 sec + sortall = ((argc < 3) ? 1 : atoi(argv[2])); while( 1 ){ if( (pid = fork()) != 0 ){ @@ -287,8 +298,14 @@ int utmpsortd(int argc, char **argv) for( i = 0 ; SHM->UTMPbusystate && i < 5 ; ++i ) usleep(300000); - if( SHM->UTMPneedsort ) - utmpsort(); + if( SHM->UTMPneedsort ){ + if( ++counter == sortall ){ + utmpsort(1); + counter = 0; + } + else + utmpsort(0); + } usleep(interval); } |