RPM Package Manager, CVS Repository
  http://rpm5.org/cvs/
  ____________________________________________________________________________

  Server: rpm5.org                         Name:   Jeff Johnson
  Root:   /v/rpm/cvs                       Email:  j...@rpm5.org
  Module: rpm                              Date:   21-Jun-2017 08:40:28
  Branch: rpm-5_4                          Handle: 2017062106402800

  Modified files:           (Branch: rpm-5_4)
    rpm/rpmio               librpmio.vers rpmeio.c rpmeio.h teio.c

  Log:
    - rpmeio: cross-reference evl/loop/req as much as possible.
    - rpmeio: add zlog tracing.

  Summary:
    Revision    Changes     Path
    2.199.2.97  +1  -0      rpm/rpmio/librpmio.vers
    1.1.2.7     +132 -44    rpm/rpmio/rpmeio.c
    1.1.2.6     +5  -2      rpm/rpmio/rpmeio.h
    1.1.2.12    +3  -10     rpm/rpmio/teio.c
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: rpm/rpmio/librpmio.vers
  ============================================================================
  $ cvs diff -u -r2.199.2.96 -r2.199.2.97 librpmio.vers
  --- rpm/rpmio/librpmio.vers   21 Jun 2017 03:34:46 -0000      2.199.2.96
  +++ rpm/rpmio/librpmio.vers   21 Jun 2017 06:40:28 -0000      2.199.2.97
  @@ -474,6 +474,7 @@
       rpmMCExpand;
       rpmMCExpandNumeric;
       _rpmeio_debug;
  +    rpmeioDrain;
       rpmeioDumpREQ;
       rpmeioLoop;
       rpmeioNew;
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/rpmeio.c
  ============================================================================
  $ cvs diff -u -r1.1.2.6 -r1.1.2.7 rpmeio.c
  --- rpm/rpmio/rpmeio.c        21 Jun 2017 03:34:47 -0000      1.1.2.6
  +++ rpm/rpmio/rpmeio.c        21 Jun 2017 06:40:28 -0000      1.1.2.7
  @@ -5,6 +5,7 @@
   #endif
   
   #include <rpmio.h>
  +#include <rpmzlog.h>
   #include <poptIO.h>
   
   #define      _RPMEIO_INTERNAL
  @@ -19,7 +20,11 @@
   
   #define SPEW(_fmt, ...) \
       if (_rpmeio_debug || _rpmio_debug) \
  -     fprintf(stderr, _fmt, __VA_ARGS__)
  +     fprintf(stderr, _fmt "\n", __VA_ARGS__)
  +
  +#define ZSPEW(_fmt, ...) \
  +    if (zlog) \
  +     rpmzLogAdd(zlog, _fmt, __VA_ARGS__)
   
   #define REQ_ERRNO(req)               ((req)->errorno)
   
  @@ -84,6 +89,10 @@
       if (msg) fprintf(stderr, "========================== %s(%p)\n", msg, 
req);
   
       if (req) {
  +     rpmeio eio = (rpmeio) (((rpmioItem)req) - 1);
  +
  +     if (eio->evl)
  +         fprintf(fp, "%25s: %p\n", "evl", eio->evl);
   
   #define PRINT(_fmt, _foo) \
       {   fprintf(fp, "%25s: %"#_fmt"\n", #_foo, req->_foo); }
  @@ -171,12 +180,6 @@
   
   #undef       USE_PIPE
   
  -#if !defined(USE_PIPE)
  -static ev_idle repeat_watcher;
  -static ev_async ready_watcher;
  -#endif
  -
  -typedef struct rpmevl_s *rpmevl;
   struct rpmevl_s {
   #if defined(USE_PIPE)
       int pipefdno[2];
  @@ -187,16 +190,28 @@
       rpmev idle_ev;
       rpmev async_ev;
   #endif
  +    rpmzLog zlog;            /*!< high precision timestamp'd log */
   };
   static struct rpmevl_s _evl;
  -static rpmevl evl = &_evl;
  +
  +static rpmevl rpmevlGet(void)
  +{
  +#if defined(USE_PIPE)
  +    return &_evl;
  +#else
  +   return (rpmevl) ev_userdata(EV_DEFAULT);
  +#endif
  +}
   
   /* idle watcher callback, only used when eio_poll */
   /* didn't handle all results in one call */
   static void
   repeat (EV_P_ ev_idle *w, int revents)
   {
  -SPEW("*** %s(%p, %p, %d)\n", __FUNCTION__, loop, w, revents);
  +    rpmevl evl = (rpmevl) ev_userdata(loop);
  +    rpmzLog zlog = evl->zlog;
  +ZSPEW("--> %s(%p, %p, %d)", __FUNCTION__, loop, w, revents);
  +
       if (eio_poll() != -1)
        ev_idle_stop (EV_A_ w);
   }
  @@ -205,10 +220,14 @@
   static void
   ready (EV_P_ ev_async *w, int revents)
   {
  -SPEW("*** %s(%p, %p, %d)\n", __FUNCTION__, loop, w, revents);
   #if !defined(USE_PIPE)
  -    if (eio_poll() == -1)
  -     ev_idle_start (EV_A_ &repeat_watcher);
  +    rpmevl evl = (rpmevl) ev_userdata(loop);
  +    rpmzLog zlog = evl->zlog;
  +ZSPEW("--> %s(%p, %p, %d)", __FUNCTION__, loop, w, revents);
  +
  +    if (eio_poll() == -1) {
  +     evl->idle_ev = rpmevNew(RPMEV_TYPE_IDLE,      NULL);
  +    }
   #endif       /* USE_PIPE */
   }
   
  @@ -216,25 +235,32 @@
   static
   void want_poll (void)
   {
  +    rpmevl evl = rpmevlGet();
  +    rpmzLog zlog = evl->zlog;
  +
   #if defined(USE_PIPE)
       char dummy = '\0';
       ssize_t nw = write(pipeout, &dummy, sizeof(dummy));
  -SPEW("<-- %s(%d) nw %zd\n", "write", pipeout, nw);
  +ZSPEW("<-- %s(%d) nw %zd", "write", pipeout, nw);
   #else
  -    ev_async_send(evl->loop, &ready_watcher);
  -SPEW("*** %s() loop %p)\n", __FUNCTION__, evl->loop);
  +    ev_async * w = &evl->async_ev->evw.async;
  +    ev_async_send(evl->loop, w);
  +ZSPEW("<-- %s()", __FUNCTION__);
   #endif
   }
   
   static
   void done_poll(void)
   {
  +    rpmevl evl = rpmevlGet();
  +    rpmzLog zlog = evl->zlog;
  +
   #if defined(USE_PIPE)
       char dummy = '\0';
       ssize_t nr = read(pipein, &dummy, sizeof(dummy));
  -SPEW("*** %s(%d) nr %zd nthreads:%u nreqs:%u nready:%u npending:%u\n", " 
read", pipein, nr, eio_nthreads(), eio_nreqs(), eio_nready(), eio_npending());
  +ZSPEW("<-- %s(%d) nr %zd nthreads:%u nreqs:%u nready:%u npending:%u", " 
read", pipein, nr, eio_nthreads(), eio_nreqs(), eio_nready(), eio_npending());
   #else
  -SPEW("*** %s() loop %p nthreads:%u nreqs:%u nready:%u npending:%u\n", 
__FUNCTION__, evl->loop, eio_nthreads(), eio_nreqs(), eio_nready(), 
eio_npending());
  +ZSPEW("<-- %s() nthreads:%u nreqs:%u nready:%u npending:%u", __FUNCTION__, 
eio_nthreads(), eio_nreqs(), eio_nready(), eio_npending());
   #endif       /* USE_PIPE */
   }
   
  @@ -264,10 +290,13 @@
   
   #endif       /* TODO */
   
  -int rpmeioStart(void * _evl)
  +rpmevl rpmeioStart(unsigned flags)
   {
       int rc;
  +
   #if defined(USE_PIPE)
  +    rpmevl evl = &_evl;
  +
       evl->pipefdno[0] = -1;
       evl->pipefdno[1] = -1;
       rc = pipe(evl->pipefdno);
  @@ -275,66 +304,98 @@
       if (!rc)
        rc = eio_init(want_poll, done_poll);
   
  -SPEW("<-- %s(%p) rc %d pipe [%d,%d]\n", __FUNCTION__, _evl, rc, 
evl->pipefdno[0], evl->pipefdno[1]);
  +SPEW("<-- %s() evl %p pipe [%d,%d]", __FUNCTION__, evl, evl->pipefdno[0], 
evl->pipefdno[1]);
   
   #else        /* USE_PIPE */
  +    rpmevl evl = xcalloc(1, sizeof(*evl));
   
       evl->loop = ev_default_loop(EVFLAG_AUTO);
  +    ev_set_userdata(evl->loop, evl);
   
  -    ev_idle_init (&repeat_watcher, repeat);
  -    ev_async_init (&ready_watcher, ready);
  -    ev_async_start (evl->loop, &ready_watcher);
  -ev_run(evl->loop, EVRUN_NOWAIT);
  +    evl->async_ev = rpmevNew(RPMEV_TYPE_ASYNC,     ready);
   
       rc = eio_init (want_poll, done_poll);
   
  -SPEW("<-- %s(%p) rc %d loop %p\n", __FUNCTION__, _evl, rc, evl->loop);
  +SPEW("<-- %s() evl %p loop %p", __FUNCTION__, evl, evl->loop);
   
   #endif       /* USE_PIPE */
   
  -    return rc;
  +    evl->zlog = (_rpmeio_debug || _rpmio_debug) ? rpmzLogNew(NULL) : NULL;
  +
  +    return evl;
   }
   
  -void rpmeioLoop(void * _eioloop)
  +void rpmeioLoop(rpmevl evl)
   {
  +    rpmzLog zlog = (evl ? evl->zlog : NULL);
       int npolls = 0;
   
  -SPEW("==> %s()\n", __FUNCTION__);
  +ZSPEW("==> %s()", __FUNCTION__);
   
   #if defined(USE_PIPE)
  +
       struct pollfd pfd;
       pfd.fd = pipein;
       pfd.events = POLLIN;
   
  -    while (eio_nreqs()) {
  +    while (eio_nreqs() > 0) {
        int xx = poll(&pfd, 1, -1);
        (void)xx;
        npolls = eio_poll();
       }
   #else
  -    while (eio_nreqs()) {
  -SPEW("*** %s() loop %p nthreads:%u nreqs:%u nready:%u npending:%u\n", 
__FUNCTION__, evl->loop, eio_nthreads(), eio_nreqs(), eio_nready(), 
eio_npending());
  +
  +    while (eio_nreqs() > 0) {
  +ZSPEW("*** %s() nthreads:%u nreqs:%u nready:%u npending:%u", __FUNCTION__, 
eio_nthreads(), eio_nreqs(), eio_nready(), eio_npending());
        ev_run(evl->loop, EVRUN_ONCE);
        npolls++;
       }
   #endif       /* USE_PIPE */
   
  -SPEW("<== %s() npolls %d\n", __FUNCTION__, npolls);
  +ZSPEW("<== %s() npolls %d", __FUNCTION__, npolls);
  +}
  +
  +void rpmeioDrain(rpmevl evl)
  +{
  +    while (eio_nreqs() > 0)
  +     rpmeioLoop(evl);
  +
  +#if defined(USE_PIPE)
  +#else
  +    if (evl->idle_ev)
  +     evl->idle_ev = rpmevFree(evl->idle_ev);
  +    if (evl->async_ev)
  +     evl->async_ev = rpmevFree(evl->async_ev);
  +
  +    ev_loop_destroy(evl->loop);
  +#endif       /* !USE_PIPE */
  +
  +fprintf(stderr, "***************************************\n");
  +    if (evl->zlog)
  +     evl->zlog = rpmzLogDump(evl->zlog, NULL);
  +fprintf(stderr, "***************************************\n");
  +
  +    memset(evl, 0, sizeof(*evl));
  +    if (evl != &_evl)
  +     evl = _free(evl);
  +
   }
   
   void Eio_cancel(eio_req * req)
   {
       rpmeio eio = (rpmeio) (((rpmioItem)req) - 1);
  -SPEW("--> %s(%p) eio %p\n", __FUNCTION__, req, eio);
  +SPEW("--> %s(%p) eio %p", __FUNCTION__, req, eio);
       eio_cancel(req);
   }
   
   void Eio_destroy(eio_req * req)
   {
       rpmeio eio = (rpmeio) (((rpmioItem)req) - 1);
  -SPEW("--> %s(%p) eio %p\n", __FUNCTION__, req, eio);
  +SPEW("--> %s(%p) eio %p", __FUNCTION__, req, eio);
   
       /* XXX wipe variables to shorten rpmeioDumpREQ() spewage. */
  +    eio->evl = NULL;
  +
       req->next = NULL;
       req->result = 0;
       req->errorno = 0;
  @@ -353,6 +414,7 @@
       req->int3 = 0;
       req->finish = NULL;
       req->destroy = NULL;
  +
   rpmeioDumpREQ(__FUNCTION__, req, NULL);
   
       do {
  @@ -364,13 +426,15 @@
   eio_req * Eio_submit(eio_req * req)
   {
       rpmeio eio = (rpmeio) (((rpmioItem)req) - 1);
  +    rpmevl evl = (rpmevl) eio->evl;
  +    rpmzLog zlog = (evl ? evl->zlog : NULL);
   #ifdef       NOTYET
       eio = rpmeioLink(eio);
   #endif
   assert(req == &eio->req);
       req = &eio->req;
       eio_submit(req);
  -SPEW("<-- %s(%p) eio %p\n", __FUNCTION__, req, eio);
  +ZSPEW("<-- %s(%p) eio %p", __FUNCTION__, req, eio);
       return req;
   }
   
  @@ -378,7 +442,14 @@
   int rpmeioCB(eio_req * req)
   {
       rpmeio eio = (rpmeio) (((rpmioItem)req) - 1);
  -SPEW("--> %s(%s|%p) res %ld eio %p\n", __FUNCTION__, REQ_TYPE(req), 
REQ_DATA(req), EIO_RESULT(req), eio);
  +    rpmevl evl = (rpmevl) eio->evl;
  +    rpmzLog zlog = (evl ? evl->zlog : NULL);
  +ZSPEW("--> %s(%s|%p) res %ld eio %p", __FUNCTION__, REQ_TYPE(req), 
REQ_DATA(req), EIO_RESULT(req), eio);
  +
  +    if (req->type == EIO_READLINK && req->result >= 0) {
  +     char * b = (char *) EIO_BUF(req);
  +     b[req->result] = '\0';
  +    }
   
   rpmeioDumpREQ(__FUNCTION__, req, NULL);
   
  @@ -397,16 +468,18 @@
   int rpmeioCB_readdir(eio_req * req)
   {
       rpmeio eio = (rpmeio) (((rpmioItem)req) - 1);
  +    rpmevl evl = (rpmevl) eio->evl;
  +    rpmzLog zlog = (evl ? evl->zlog : NULL);
       char *buf = (char *) EIO_BUF(req);
   
  -SPEW("--> %s(%s|%p) res %ld eio %p\n", __FUNCTION__, REQ_TYPE(req), 
REQ_DATA(req), EIO_RESULT(req), eio);
  +ZSPEW("--> %s(%s|%p) res %ld eio %p", __FUNCTION__, REQ_TYPE(req), 
REQ_DATA(req), EIO_RESULT(req), eio);
   rpmeioDumpREQ(__FUNCTION__, req, NULL);
   
       if (EIO_RESULT(req) < 0)
        return 0;
   
       while (EIO_RESULT(req)--) {
  -     SPEW("\treaddir = <%s>\n", buf);
  +     SPEW("\treaddir = <%s>", buf);
        buf += strlen(buf) + 1;
       }
   
  @@ -420,18 +493,21 @@
   int rpmeioCB_stat(eio_req * req)
   {
       rpmeio eio = (rpmeio) (((rpmioItem)req) - 1);
  +    rpmevl evl = (rpmevl) eio->evl;
  +    rpmzLog zlog = (evl ? evl->zlog : NULL);
       struct stat *buf = EIO_STAT_BUF(req);
   
  -SPEW("--> %s(%s|%p) res %ld eio %p\n", __FUNCTION__, REQ_TYPE(req), 
REQ_DATA(req), EIO_RESULT(req), eio);
  +ZSPEW("--> %s(%s|%p) res %ld eio %p", __FUNCTION__, REQ_TYPE(req), 
REQ_DATA(req), EIO_RESULT(req), eio);
   rpmeioDumpREQ(__FUNCTION__, req, NULL);
  +
       if (req->type == EIO_FSTAT) {
  -     SPEW("\tfstat = %ld\n", EIO_RESULT(req));
  +     SPEW("\tfstat = %ld", EIO_RESULT(req));
       } else {
  -     SPEW("\tstat(%s) = %ld\n", EIO_PATH(req), EIO_RESULT(req));
  +     SPEW("\tstat(%s) = %ld", EIO_PATH(req), EIO_RESULT(req));
       }
   
       if (!EIO_RESULT(req))
  -     SPEW("\tstat size %ld perm 0%o\n", buf->st_size,
  +     SPEW("\tstat size %ld perm 0%o", buf->st_size,
               buf->st_mode & 0777);
   
   #ifdef       NOTYET
  @@ -444,9 +520,11 @@
   int rpmeioCB_read(eio_req * req)
   {
       rpmeio eio = (rpmeio) (((rpmioItem)req) - 1);
  +    rpmevl evl = (rpmevl) eio->evl;
  +    rpmzLog zlog = (evl ? evl->zlog : NULL);
       unsigned char *buf = (unsigned char *) EIO_BUF(req);
   
  -SPEW("--> %s(%s|%p) res %ld eio %p (%02x%02x%02x%02x %02x%02x%02x%02x)\n",
  +ZSPEW("--> %s(%s|%p) res %ld eio %p (%02x%02x%02x%02x %02x%02x%02x%02x)",
        __FUNCTION__, REQ_TYPE(req), REQ_DATA(req), EIO_RESULT(req), eio,
        buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]);
   rpmeioDumpREQ(__FUNCTION__, req, NULL);
  @@ -463,7 +541,9 @@
   int rpmeioCB_open(eio_req * req)
   {
       rpmeio eio = (rpmeio) (((rpmioItem)req) - 1);
  -SPEW("--> %s(%s|%p) res %ld eio %p\n", __FUNCTION__, REQ_TYPE(req), 
REQ_DATA(req), EIO_RESULT(req), eio);
  +    rpmevl evl = (rpmevl) eio->evl;
  +    rpmzLog zlog = (evl ? evl->zlog : NULL);
  +ZSPEW("--> %s(%s|%p) res %ld eio %p", __FUNCTION__, REQ_TYPE(req), 
REQ_DATA(req), EIO_RESULT(req), eio);
   rpmeioDumpREQ(__FUNCTION__, req, NULL);
   
       rpmeioLastFdno = EIO_RESULT(req);
  @@ -479,6 +559,8 @@
   eio_req * Eio_request(int reqtype, ...)
   {
       rpmeio eio = NULL;
  +    rpmevl evl = NULL;
  +    rpmzLog zlog = NULL;
       eio_req * req = NULL;
   
       int pri = 0;
  @@ -489,6 +571,8 @@
        goto exit;
   
       eio = rpmeioNew(reqtype);
  +    evl = eio->evl;
  +    zlog = (evl ? evl->zlog : NULL);
       req = &eio->req;
   
       va_list ap;
  @@ -832,7 +916,7 @@
   rpmeioDumpREQ(__FUNCTION__, req, NULL);
   
   exit:
  -SPEW("<-- %s(%s|%p) req %p\n", __FUNCTION__, REQ_TYPE(req), REQ_DATA(req), 
req);
  +ZSPEW("<-- %s(%s|%p) req %p", __FUNCTION__, REQ_TYPE(req), REQ_DATA(req), 
req);
   
       return req;
   }
  @@ -1112,6 +1196,8 @@
        eio->req.grp_next = NULL;
        eio->req.grp_first = NULL;
   
  +     eio->evl = NULL;
  +
       }
   }
   
  @@ -1152,5 +1238,7 @@
        eio->req.grp_next = NULL;
        eio->req.grp_first = NULL;
   
  +    eio->evl = (void *) rpmevlGet();
  +
       return rpmeioLink(eio);
   }
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/rpmeio.h
  ============================================================================
  $ cvs diff -u -r1.1.2.5 -r1.1.2.6 rpmeio.h
  --- rpm/rpmio/rpmeio.h        21 Jun 2017 03:34:47 -0000      1.1.2.5
  +++ rpm/rpmio/rpmeio.h        21 Jun 2017 06:40:28 -0000      1.1.2.6
  @@ -8,6 +8,7 @@
   extern int _rpmeio_debug;
   
   typedef      struct rpmeio_s * rpmeio;
  +typedef struct rpmevl_s * rpmevl;
   
   /**
    */
  @@ -86,6 +87,7 @@
   struct rpmeio_s {
       struct rpmioItem_s _item;        /*!< usage mutex and pool identifier. */
       eio_req req;
  +    void * evl;
   };
   
   RPM_GNUC_CONST
  @@ -95,8 +97,9 @@
   
   extern void rpmeioDumpREQ(const char *msg, eio_req * req, FILE *fp);
   
  -int rpmeioStart(void * evl);
  -void rpmeioLoop(void * evl);
  +rpmevl rpmeioStart(unsigned flags);
  +void rpmeioLoop(rpmevl evl);
  +void rpmeioDrain(rpmevl evl);
   
   void Eio_cancel(eio_req * req);
   void Eio_destroy(eio_req * req);
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/teio.c
  ============================================================================
  $ cvs diff -u -r1.1.2.11 -r1.1.2.12 teio.c
  --- rpm/rpmio/teio.c  21 Jun 2017 03:34:47 -0000      1.1.2.11
  +++ rpm/rpmio/teio.c  21 Jun 2017 06:40:28 -0000      1.1.2.12
  @@ -158,11 +158,9 @@
   static int doEIO(ARGV_t av, int ac)
   {
       int rc = 0;
  -    void * evl = NULL;
  +    unsigned flags = 0;
   
  -    rc = rpmeioStart(evl);
  -    if (rc)
  -     goto exit;
  +    rpmevl evl = rpmeioStart(flags);
   
       do {
        /* avoid relative paths yourself(!) */
  @@ -235,15 +233,10 @@
   
       } while (0);
   
  -    while (eio_nreqs() > 0) {
  -fprintf(stderr, "***************************************\n");
  -rpmeioLoop(evl); sleep(1);
  -    }
  -fprintf(stderr, "***************************************\n");
  +    rpmeioDrain(evl);
   
       rc = 0;  /* XXX */
   
  -exit:
       return rc;
   }
   
  @@ .
______________________________________________________________________
RPM Package Manager                                    http://rpm5.org
CVS Sources Repository                                rpm-cvs@rpm5.org

Reply via email to