You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by ok...@apache.org on 2018/03/03 11:43:49 UTC

[trafficserver] branch master updated: Optimize: define AIO_Reqs::aio_temp_list by ASLL macro

This is an automated email from the ASF dual-hosted git repository.

oknet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new a600975  Optimize: define AIO_Reqs::aio_temp_list by ASLL macro
a600975 is described below

commit a60097569fa433c406439f94a35259274f54d697
Author: Oknet Xu <xu...@skyguard.com.cn>
AuthorDate: Thu Feb 22 20:02:12 2018 +0800

    Optimize: define AIO_Reqs::aio_temp_list by ASLL macro
---
 iocore/aio/AIO.cc  | 48 +++++++++++++++++-------------------------------
 iocore/aio/I_AIO.h |  8 +-------
 iocore/aio/P_AIO.h | 23 ++++++++++++++---------
 3 files changed, 32 insertions(+), 47 deletions(-)

diff --git a/iocore/aio/AIO.cc b/iocore/aio/AIO.cc
index e760354..0e7f15a 100644
--- a/iocore/aio/AIO.cc
+++ b/iocore/aio/AIO.cc
@@ -221,15 +221,12 @@ aio_init_fildes(int fildes, int fromAPI = 0)
 {
   char thr_name[MAX_THREAD_NAME_LENGTH];
   int i;
-  AIO_Reqs *request = (AIO_Reqs *)ats_malloc(sizeof(AIO_Reqs));
-
-  memset(request, 0, sizeof(AIO_Reqs));
+  AIO_Reqs *request = new AIO_Reqs;
 
   INK_WRITE_MEMORY_BARRIER;
 
   ink_cond_init(&request->aio_cond);
   ink_mutex_init(&request->aio_mutex);
-  ink_atomiclist_init(&request->aio_temp_list, "temp_list", (uintptr_t) & ((AIOCallback *)nullptr)->link);
 
   RecInt thread_num;
 
@@ -280,12 +277,7 @@ aio_insert(AIOCallback *op, AIO_Reqs *req)
 #endif
   if (op->aiocb.aio_reqprio == AIO_LOWEST_PRIORITY) // http request
   {
-    AIOCallback *cb = (AIOCallback *)req->http_aio_todo.tail;
-    if (!cb) {
-      req->http_aio_todo.push(op);
-    } else {
-      req->http_aio_todo.insert(op, cb);
-    }
+    req->http_aio_todo.enqueue(op);
   } else {
     AIOCallback *cb = (AIOCallback *)req->aio_todo.tail;
 
@@ -305,23 +297,21 @@ aio_insert(AIOCallback *op, AIO_Reqs *req)
 static void
 aio_move(AIO_Reqs *req)
 {
-  AIOCallback *next = nullptr, *prev = nullptr, *cb = (AIOCallback *)ink_atomiclist_popall(&req->aio_temp_list);
-  /* flip the list */
-  if (!cb) {
+  if (req->aio_temp_list.empty()) {
     return;
   }
-  while (cb->link.next) {
-    next          = (AIOCallback *)cb->link.next;
-    cb->link.next = prev;
-    prev          = cb;
-    cb            = next;
+
+  AIOCallbackInternal *cbi;
+  SList(AIOCallbackInternal, alink) aq(req->aio_temp_list.popall());
+
+  // flip the list
+  Queue<AIOCallback> cbq;
+  while ((cbi = aq.pop())) {
+    cbq.push(cbi);
   }
-  /* fix the last pointer */
-  cb->link.next = prev;
-  for (; cb; cb = next) {
-    next          = (AIOCallback *)cb->link.next;
-    cb->link.next = nullptr;
-    cb->link.prev = nullptr;
+
+  AIOCallback *cb;
+  while ((cb = cbq.pop())) {
     aio_insert(cb, req);
   }
 }
@@ -385,15 +375,13 @@ aio_queue_req(AIOCallbackInternal *op, int fromAPI = 0)
 #ifdef AIO_STATS
     ink_atomic_increment(&data->num_temp, 1);
 #endif
-    ink_atomiclist_push(&req->aio_temp_list, op);
+    req->aio_temp_list.push(op);
   } else {
 /* check if any pending requests on the atomic list */
 #ifdef AIO_STATS
     ink_atomic_increment(&data->num_queue, 1);
 #endif
-    if (!INK_ATOMICLIST_EMPTY(req->aio_temp_list)) {
-      aio_move(req);
-    }
+    aio_move(req);
     /* now put the new request */
     aio_insert(op, req);
     ink_cond_signal(&req->aio_cond);
@@ -475,9 +463,7 @@ aio_thread_main(void *arg)
       }
       current_req = my_aio_req;
       /* check if any pending requests on the atomic list */
-      if (!INK_ATOMICLIST_EMPTY(my_aio_req->aio_temp_list)) {
-        aio_move(my_aio_req);
-      }
+      aio_move(my_aio_req);
       if (!(op = my_aio_req->aio_todo.pop()) && !(op = my_aio_req->http_aio_todo.pop())) {
         break;
       }
diff --git a/iocore/aio/I_AIO.h b/iocore/aio/I_AIO.h
index f7f98f4..70d5c6f 100644
--- a/iocore/aio/I_AIO.h
+++ b/iocore/aio/I_AIO.h
@@ -102,13 +102,7 @@ struct AIOCallback : public Continuation {
   int64_t aio_result = 0;
 
   int ok();
-  AIOCallback()
-  {
-    aiocb.aio_reqprio = AIO_DEFAULT_PRIORITY;
-#if AIO_MODE == AIO_MODE_NATIVE
-    memset((void *)&(this->aiocb), 0, sizeof(this->aiocb));
-#endif
-  }
+  AIOCallback() {}
 };
 
 #if AIO_MODE == AIO_MODE_NATIVE
diff --git a/iocore/aio/P_AIO.h b/iocore/aio/P_AIO.h
index 696d9b5..edc28fa 100644
--- a/iocore/aio/P_AIO.h
+++ b/iocore/aio/P_AIO.h
@@ -54,7 +54,7 @@ struct AIOCallbackInternal : public AIOCallback {
   int io_complete(int event, void *data);
   AIOCallbackInternal()
   {
-    memset((char *)&(this->aiocb), 0, sizeof(this->aiocb));
+    memset((void *)&(this->aiocb), 0, sizeof(this->aiocb));
     SET_HANDLER(&AIOCallbackInternal::io_complete);
   }
 };
@@ -81,12 +81,17 @@ AIOVec::mainEvent(int /* event */, Event *)
 struct AIO_Reqs;
 
 struct AIOCallbackInternal : public AIOCallback {
-  AIOCallback *first    = nullptr;
   AIO_Reqs *aio_req     = nullptr;
   ink_hrtime sleep_time = 0;
+  SLINK(AIOCallbackInternal, alink); /* for AIO_Reqs::aio_temp_list */
+
   int io_complete(int event, void *data);
 
-  AIOCallbackInternal() { SET_HANDLER(&AIOCallbackInternal::io_complete); }
+  AIOCallbackInternal()
+  {
+    aiocb.aio_reqprio = AIO_DEFAULT_PRIORITY;
+    SET_HANDLER(&AIOCallbackInternal::io_complete);
+  }
 };
 
 struct AIO_Reqs {
@@ -94,14 +99,14 @@ struct AIO_Reqs {
   Que(AIOCallback, link) http_aio_todo; /* queue for http requests */
                                         /* Atomic list to temporarily hold the request if the
                                            lock for a particular queue cannot be acquired */
-  InkAtomicList aio_temp_list;
+  ASLL(AIOCallbackInternal, alink) aio_temp_list;
   ink_mutex aio_mutex;
   ink_cond aio_cond;
-  int index;   /* position of this struct in the aio_reqs array */
-  int pending; /* number of outstanding requests on the disk */
-  int queued;  /* total number of aio_todo and http_todo requests */
-  int filedes; /* the file descriptor for the requests */
-  int requests_queued;
+  int index           = 0; /* position of this struct in the aio_reqs array */
+  int pending         = 0; /* number of outstanding requests on the disk */
+  int queued          = 0; /* total number of aio_todo and http_todo requests */
+  int filedes         = 0; /* the file descriptor for the requests */
+  int requests_queued = 0;
 };
 
 #endif // AIO_MODE == AIO_MODE_NATIVE

-- 
To stop receiving notification emails like this one, please contact
oknet@apache.org.