Permalink
Browse files

TS-2156: Fix stats trap in different type of threads

There are two ways to create threads in ATS:
1) By EventProcessor::spawn_event_threads(), such as ET_NET threads.
2) By EventProcessor::spawn_thread(), such as flush thread.

But I found that we can't stats the same things across these two type of
threads.

This patch will make stats in both type of threads transparent for upper
layer developers.

BTW: renames "dthreads" to "all_dthreads" to keep naming consistency with
     "all_ethreads".

Signed-off-by: Yunkai Zhang <qiushu.zyk@taobao.com>
  • Loading branch information...
1 parent 4633563 commit fb20be5250272d010503a0a642d7f1deaa17d065 @yunkai yunkai committed Aug 26, 2013
View
2 CHANGES
@@ -2,6 +2,8 @@
Changes with Apache Traffic Server 4.1.0
+ *) [TS-2156] Fix stats trap in different type of threads
+
*) [TS-2160] Remove ats_is_ip_nonroutable and replace it with the less confusing
ats_is_ip_linklocal and ats_is_ip_private.
View
2 iocore/eventsystem/I_EventProcessor.h
@@ -314,7 +314,7 @@ class EventProcessor:public Processor
Event * schedule(Event * e, EventType etype, bool fast_signal = false);
EThread *assign_thread(EventType etype);
- EThread *dthreads[MAX_EVENT_THREADS];
+ EThread *all_dthreads[MAX_EVENT_THREADS];
int n_dthreads; // No. of dedicated threads
volatile int thread_data_used;
};
View
2 iocore/eventsystem/P_UnixEventProcessor.h
@@ -36,7 +36,7 @@ n_dthreads(0),
thread_data_used(0)
{
memset(all_ethreads, 0, sizeof(all_ethreads));
- memset(dthreads, 0, sizeof(dthreads));
+ memset(all_dthreads, 0, sizeof(all_dthreads));
memset(n_threads_for_type, 0, sizeof(n_threads_for_type));
memset(next_thread_for_type, 0, sizeof(next_thread_for_type));
}
View
6 iocore/eventsystem/UnixEventProcessor.cc
@@ -223,9 +223,9 @@ EventProcessor::spawn_thread(Continuation *cont, const char* thr_name, size_t st
Event *e = eventAllocator.alloc();
e->init(cont, 0, 0);
- dthreads[n_dthreads] = NEW(new EThread(DEDICATED, e, sem));
- e->ethread = dthreads[n_dthreads];
- e->mutex = e->continuation->mutex = dthreads[n_dthreads]->mutex;
+ all_dthreads[n_dthreads] = NEW(new EThread(DEDICATED, e, sem));
+ e->ethread = all_dthreads[n_dthreads];
+ e->mutex = e->continuation->mutex = all_dthreads[n_dthreads]->mutex;
n_dthreads++;
e->ethread->start(thr_name, stacksize);
View
33 lib/records/RecProcess.cc
@@ -117,6 +117,13 @@ raw_stat_get_total(RecRawStatBlock *rsb, int id, RecRawStat *total)
total->sum += tlp->sum;
total->count += tlp->count;
}
+
+ for (i = 0; i < eventProcessor.n_dthreads; i++) {
+ tlp = ((RecRawStat *) ((char *) (eventProcessor.all_dthreads[i]) + rsb->ethr_stat_offset)) + id;
+ total->sum += tlp->sum;
+ total->count += tlp->count;
+ }
+
if (total->sum < 0) { // Assure that we stay positive
total->sum = 0;
}
@@ -144,6 +151,13 @@ raw_stat_sync_to_global(RecRawStatBlock *rsb, int id)
total.sum += tlp->sum;
total.count += tlp->count;
}
+
+ for (i = 0; i < eventProcessor.n_dthreads; i++) {
+ tlp = ((RecRawStat *) ((char *) (eventProcessor.all_dthreads[i]) + rsb->ethr_stat_offset)) + id;
+ total.sum += tlp->sum;
+ total.count += tlp->count;
+ }
+
if (total.sum < 0) { // Assure that we stay positive
total.sum = 0;
}
@@ -198,6 +212,13 @@ raw_stat_clear(RecRawStatBlock *rsb, int id)
ink_atomic_swap(&(tlp->sum), (int64_t)0);
ink_atomic_swap(&(tlp->count), (int64_t)0);
}
+
+ for (int i = 0; i < eventProcessor.n_dthreads; i++) {
+ tlp = ((RecRawStat *) ((char *) (eventProcessor.all_dthreads[i]) + rsb->ethr_stat_offset)) + id;
+ ink_atomic_swap(&(tlp->sum), (int64_t)0);
+ ink_atomic_swap(&(tlp->count), (int64_t)0);
+ }
+
return REC_ERR_OKAY;
}
@@ -223,6 +244,12 @@ raw_stat_clear_sum(RecRawStatBlock *rsb, int id)
tlp = ((RecRawStat *) ((char *) (eventProcessor.all_ethreads[i]) + rsb->ethr_stat_offset)) + id;
ink_atomic_swap(&(tlp->sum), (int64_t)0);
}
+
+ for (int i = 0; i < eventProcessor.n_dthreads; i++) {
+ tlp = ((RecRawStat *) ((char *) (eventProcessor.all_dthreads[i]) + rsb->ethr_stat_offset)) + id;
+ ink_atomic_swap(&(tlp->sum), (int64_t)0);
+ }
+
return REC_ERR_OKAY;
}
@@ -248,6 +275,12 @@ raw_stat_clear_count(RecRawStatBlock *rsb, int id)
tlp = ((RecRawStat *) ((char *) (eventProcessor.all_ethreads[i]) + rsb->ethr_stat_offset)) + id;
ink_atomic_swap(&(tlp->count), (int64_t)0);
}
+
+ for (int i = 0; i < eventProcessor.n_dthreads; i++) {
+ tlp = ((RecRawStat *) ((char *) (eventProcessor.all_dthreads[i]) + rsb->ethr_stat_offset)) + id;
+ ink_atomic_swap(&(tlp->count), (int64_t)0);
+ }
+
return REC_ERR_OKAY;
}
View
8 proxy/StatSystem.h
@@ -410,6 +410,10 @@ global_dyn_stats[X].sum = 0
_s.count += eventProcessor.all_ethreads[_e]->global_dyn_stats[X].count; \
_s.sum += eventProcessor.all_ethreads[_e]->global_dyn_stats[X].sum; \
} \
+ for (int _e = 0; _e < eventProcessor.n_dthreads ; _e++) { \
+ _s.count += eventProcessor.all_dthreads[_e]->global_dyn_stats[X].count; \
+ _s.sum += eventProcessor.all_dthreads[_e]->global_dyn_stats[X].sum; \
+ } \
C = _s.count; \
S = _s.sum; \
} while (0)
@@ -418,13 +422,17 @@ global_dyn_stats[X].sum = 0
ink_statval_t _s = global_dyn_stats[X].count; \
for (int _e = 0; _e < eventProcessor.n_ethreads ; _e++) \
_s += eventProcessor.all_ethreads[_e]->global_dyn_stats[X].count; \
+ for (int _e = 0; _e < eventProcessor.n_dthreads ; _e++) \
+ _s += eventProcessor.all_dthreads[_e]->global_dyn_stats[X].count; \
C = _s; \
} while (0)
#define READ_GLOBAL_DYN_SUM(X,S) do { \
ink_statval_t _s = global_dyn_stats[X].sum; \
for (int _e = 0; _e < eventProcessor.n_ethreads ; _e++) \
_s += eventProcessor.all_ethreads[_e]->global_dyn_stats[X].sum; \
+ for (int _e = 0; _e < eventProcessor.n_dthreads ; _e++) \
+ _s += eventProcessor.all_dthreads[_e]->global_dyn_stats[X].sum; \
S = _s; \
} while (0)

0 comments on commit fb20be5

Please sign in to comment.