cpuworker.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. /* Copyright (c) 2003-2004, Roger Dingledine.
  2. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  3. * Copyright (c) 2007-2017, The Tor Project, Inc. */
  4. /* See LICENSE for licensing information */
  5. /**
  6. * \file cpuworker.c
  7. * \brief Uses the workqueue/threadpool code to farm CPU-intensive activities
  8. * out to subprocesses.
  9. *
  10. * The multithreading backend for this module is in workqueue.c; this module
  11. * specializes workqueue.c.
  12. *
  13. * Right now, we use this infrastructure
  14. * <ul><li>for processing onionskins in onion.c
  15. * <li>for compressing consensuses in consdiffmgr.c,
  16. * <li>and for calculating diffs and compressing them in consdiffmgr.c.
  17. * </ul>
  18. **/
  19. #include "or.h"
  20. #include "channel.h"
  21. #include "circuitbuild.h"
  22. #include "circuitlist.h"
  23. #include "connection_or.h"
  24. #include "config.h"
  25. #include "cpuworker.h"
  26. #include "crypto_rand.h"
  27. #include "crypto_util.h"
  28. #include "main.h"
  29. #include "onion.h"
  30. #include "rephist.h"
  31. #include "router.h"
  32. #include "workqueue.h"
  33. #include <event2/event.h>
  34. static void queue_pending_tasks(void);
  35. typedef struct worker_state_s {
  36. int generation;
  37. server_onion_keys_t *onion_keys;
  38. } worker_state_t;
  39. static void *
  40. worker_state_new(void *arg)
  41. {
  42. worker_state_t *ws;
  43. (void)arg;
  44. ws = tor_malloc_zero(sizeof(worker_state_t));
  45. ws->onion_keys = server_onion_keys_new();
  46. return ws;
  47. }
  48. #define worker_state_free(ws) \
  49. FREE_AND_NULL(worker_state_t, worker_state_free_, (ws))
  50. static void
  51. worker_state_free_(worker_state_t *ws)
  52. {
  53. if (!ws)
  54. return;
  55. server_onion_keys_free(ws->onion_keys);
  56. tor_free(ws);
  57. }
  58. static void
  59. worker_state_free_void(void *arg)
  60. {
  61. worker_state_free_(arg);
  62. }
  63. static replyqueue_t *replyqueue = NULL;
  64. static threadpool_t *threadpool = NULL;
  65. static struct event *reply_event = NULL;
  66. static tor_weak_rng_t request_sample_rng = TOR_WEAK_RNG_INIT;
  67. static int total_pending_tasks = 0;
  68. static int max_pending_tasks = 128;
  69. static void
  70. replyqueue_process_cb(evutil_socket_t sock, short events, void *arg)
  71. {
  72. replyqueue_t *rq = arg;
  73. (void) sock;
  74. (void) events;
  75. replyqueue_process(rq);
  76. }
  77. /** Initialize the cpuworker subsystem. It is OK to call this more than once
  78. * during Tor's lifetime.
  79. */
  80. void
  81. cpu_init(void)
  82. {
  83. if (!replyqueue) {
  84. replyqueue = replyqueue_new(0);
  85. }
  86. if (!reply_event) {
  87. reply_event = tor_event_new(tor_libevent_get_base(),
  88. replyqueue_get_socket(replyqueue),
  89. EV_READ|EV_PERSIST,
  90. replyqueue_process_cb,
  91. replyqueue);
  92. event_add(reply_event, NULL);
  93. }
  94. if (!threadpool) {
  95. /*
  96. In our threadpool implementation, half the threads are permissive and
  97. half are strict (when it comes to running lower-priority tasks). So we
  98. always make sure we have at least two threads, so that there will be at
  99. least one thread of each kind.
  100. */
  101. const int n_threads = get_num_cpus(get_options()) + 1;
  102. threadpool = threadpool_new(n_threads,
  103. replyqueue,
  104. worker_state_new,
  105. worker_state_free_void,
  106. NULL);
  107. }
  108. /* Total voodoo. Can we make this more sensible? */
  109. max_pending_tasks = get_num_cpus(get_options()) * 64;
  110. crypto_seed_weak_rng(&request_sample_rng);
  111. }
  112. /** Magic numbers to make sure our cpuworker_requests don't grow any
  113. * mis-framing bugs. */
  114. #define CPUWORKER_REQUEST_MAGIC 0xda4afeed
  115. #define CPUWORKER_REPLY_MAGIC 0x5eedf00d
  116. /** A request sent to a cpuworker. */
  117. typedef struct cpuworker_request_t {
  118. /** Magic number; must be CPUWORKER_REQUEST_MAGIC. */
  119. uint32_t magic;
  120. /** Flag: Are we timing this request? */
  121. unsigned timed : 1;
  122. /** If we're timing this request, when was it sent to the cpuworker? */
  123. struct timeval started_at;
  124. /** A create cell for the cpuworker to process. */
  125. create_cell_t create_cell;
  126. /* Turn the above into a tagged union if needed. */
  127. } cpuworker_request_t;
  128. /** A reply sent by a cpuworker. */
  129. typedef struct cpuworker_reply_t {
  130. /** Magic number; must be CPUWORKER_REPLY_MAGIC. */
  131. uint32_t magic;
  132. /** True iff we got a successful request. */
  133. uint8_t success;
  134. /** Are we timing this request? */
  135. unsigned int timed : 1;
  136. /** What handshake type was the request? (Used for timing) */
  137. uint16_t handshake_type;
  138. /** When did we send the request to the cpuworker? */
  139. struct timeval started_at;
  140. /** Once the cpuworker received the request, how many microseconds did it
  141. * take? (This shouldn't overflow; 4 billion micoseconds is over an hour,
  142. * and we'll never have an onion handshake that takes so long.) */
  143. uint32_t n_usec;
  144. /** Output of processing a create cell
  145. *
  146. * @{
  147. */
  148. /** The created cell to send back. */
  149. created_cell_t created_cell;
  150. /** The keys to use on this circuit. */
  151. uint8_t keys[CPATH_KEY_MATERIAL_LEN];
  152. /** Input to use for authenticating introduce1 cells. */
  153. uint8_t rend_auth_material[DIGEST_LEN];
  154. } cpuworker_reply_t;
  155. typedef struct cpuworker_job_u {
  156. or_circuit_t *circ;
  157. union {
  158. cpuworker_request_t request;
  159. cpuworker_reply_t reply;
  160. } u;
  161. } cpuworker_job_t;
  162. static workqueue_reply_t
  163. update_state_threadfn(void *state_, void *work_)
  164. {
  165. worker_state_t *state = state_;
  166. worker_state_t *update = work_;
  167. server_onion_keys_free(state->onion_keys);
  168. state->onion_keys = update->onion_keys;
  169. update->onion_keys = NULL;
  170. worker_state_free(update);
  171. ++state->generation;
  172. return WQ_RPL_REPLY;
  173. }
  174. /** Called when the onion key has changed so update all CPU worker(s) with
  175. * new function pointers with which a new state will be generated.
  176. */
  177. void
  178. cpuworkers_rotate_keyinfo(void)
  179. {
  180. if (!threadpool) {
  181. /* If we're a client, then we won't have cpuworkers, and we won't need
  182. * to tell them to rotate their state.
  183. */
  184. return;
  185. }
  186. if (threadpool_queue_update(threadpool,
  187. worker_state_new,
  188. update_state_threadfn,
  189. worker_state_free_void,
  190. NULL)) {
  191. log_warn(LD_OR, "Failed to queue key update for worker threads.");
  192. }
  193. }
  194. /** Indexed by handshake type: how many onionskins have we processed and
  195. * counted of that type? */
  196. static uint64_t onionskins_n_processed[MAX_ONION_HANDSHAKE_TYPE+1];
  197. /** Indexed by handshake type, corresponding to the onionskins counted in
  198. * onionskins_n_processed: how many microseconds have we spent in cpuworkers
  199. * processing that kind of onionskin? */
  200. static uint64_t onionskins_usec_internal[MAX_ONION_HANDSHAKE_TYPE+1];
  201. /** Indexed by handshake type, corresponding to onionskins counted in
  202. * onionskins_n_processed: how many microseconds have we spent waiting for
  203. * cpuworkers to give us answers for that kind of onionskin?
  204. */
  205. static uint64_t onionskins_usec_roundtrip[MAX_ONION_HANDSHAKE_TYPE+1];
  206. /** If any onionskin takes longer than this, we clip them to this
  207. * time. (microseconds) */
  208. #define MAX_BELIEVABLE_ONIONSKIN_DELAY (2*1000*1000)
  209. /** Return true iff we'd like to measure a handshake of type
  210. * <b>onionskin_type</b>. Call only from the main thread. */
  211. static int
  212. should_time_request(uint16_t onionskin_type)
  213. {
  214. /* If we've never heard of this type, we shouldn't even be here. */
  215. if (onionskin_type > MAX_ONION_HANDSHAKE_TYPE)
  216. return 0;
  217. /* Measure the first N handshakes of each type, to ensure we have a
  218. * sample */
  219. if (onionskins_n_processed[onionskin_type] < 4096)
  220. return 1;
  221. /** Otherwise, measure with P=1/128. We avoid doing this for every
  222. * handshake, since the measurement itself can take a little time. */
  223. return tor_weak_random_one_in_n(&request_sample_rng, 128);
  224. }
  225. /** Return an estimate of how many microseconds we will need for a single
  226. * cpuworker to process <b>n_requests</b> onionskins of type
  227. * <b>onionskin_type</b>. */
  228. uint64_t
  229. estimated_usec_for_onionskins(uint32_t n_requests, uint16_t onionskin_type)
  230. {
  231. if (onionskin_type > MAX_ONION_HANDSHAKE_TYPE) /* should be impossible */
  232. return 1000 * (uint64_t)n_requests;
  233. if (PREDICT_UNLIKELY(onionskins_n_processed[onionskin_type] < 100)) {
  234. /* Until we have 100 data points, just asssume everything takes 1 msec. */
  235. return 1000 * (uint64_t)n_requests;
  236. } else {
  237. /* This can't overflow: we'll never have more than 500000 onionskins
  238. * measured in onionskin_usec_internal, and they won't take anything near
  239. * 1 sec each, and we won't have anything like 1 million queued
  240. * onionskins. But that's 5e5 * 1e6 * 1e6, which is still less than
  241. * UINT64_MAX. */
  242. return (onionskins_usec_internal[onionskin_type] * n_requests) /
  243. onionskins_n_processed[onionskin_type];
  244. }
  245. }
  246. /** Compute the absolute and relative overhead of using the cpuworker
  247. * framework for onionskins of type <b>onionskin_type</b>.*/
  248. static int
  249. get_overhead_for_onionskins(uint32_t *usec_out, double *frac_out,
  250. uint16_t onionskin_type)
  251. {
  252. uint64_t overhead;
  253. *usec_out = 0;
  254. *frac_out = 0.0;
  255. if (onionskin_type > MAX_ONION_HANDSHAKE_TYPE) /* should be impossible */
  256. return -1;
  257. if (onionskins_n_processed[onionskin_type] == 0 ||
  258. onionskins_usec_internal[onionskin_type] == 0 ||
  259. onionskins_usec_roundtrip[onionskin_type] == 0)
  260. return -1;
  261. overhead = onionskins_usec_roundtrip[onionskin_type] -
  262. onionskins_usec_internal[onionskin_type];
  263. *usec_out = (uint32_t)(overhead / onionskins_n_processed[onionskin_type]);
  264. *frac_out = U64_TO_DBL(overhead) / onionskins_usec_internal[onionskin_type];
  265. return 0;
  266. }
  267. /** If we've measured overhead for onionskins of type <b>onionskin_type</b>,
  268. * log it. */
  269. void
  270. cpuworker_log_onionskin_overhead(int severity, int onionskin_type,
  271. const char *onionskin_type_name)
  272. {
  273. uint32_t overhead;
  274. double relative_overhead;
  275. int r;
  276. r = get_overhead_for_onionskins(&overhead, &relative_overhead,
  277. onionskin_type);
  278. if (!overhead || r<0)
  279. return;
  280. log_fn(severity, LD_OR,
  281. "%s onionskins have averaged %u usec overhead (%.2f%%) in "
  282. "cpuworker code ",
  283. onionskin_type_name, (unsigned)overhead, relative_overhead*100);
  284. }
  285. /** Handle a reply from the worker threads. */
  286. static void
  287. cpuworker_onion_handshake_replyfn(void *work_)
  288. {
  289. cpuworker_job_t *job = work_;
  290. cpuworker_reply_t rpl;
  291. or_circuit_t *circ = NULL;
  292. tor_assert(total_pending_tasks > 0);
  293. --total_pending_tasks;
  294. /* Could avoid this, but doesn't matter. */
  295. memcpy(&rpl, &job->u.reply, sizeof(rpl));
  296. tor_assert(rpl.magic == CPUWORKER_REPLY_MAGIC);
  297. if (rpl.timed && rpl.success &&
  298. rpl.handshake_type <= MAX_ONION_HANDSHAKE_TYPE) {
  299. /* Time how long this request took. The handshake_type check should be
  300. needless, but let's leave it in to be safe. */
  301. struct timeval tv_end, tv_diff;
  302. int64_t usec_roundtrip;
  303. tor_gettimeofday(&tv_end);
  304. timersub(&tv_end, &rpl.started_at, &tv_diff);
  305. usec_roundtrip = ((int64_t)tv_diff.tv_sec)*1000000 + tv_diff.tv_usec;
  306. if (usec_roundtrip >= 0 &&
  307. usec_roundtrip < MAX_BELIEVABLE_ONIONSKIN_DELAY) {
  308. ++onionskins_n_processed[rpl.handshake_type];
  309. onionskins_usec_internal[rpl.handshake_type] += rpl.n_usec;
  310. onionskins_usec_roundtrip[rpl.handshake_type] += usec_roundtrip;
  311. if (onionskins_n_processed[rpl.handshake_type] >= 500000) {
  312. /* Scale down every 500000 handshakes. On a busy server, that's
  313. * less impressive than it sounds. */
  314. onionskins_n_processed[rpl.handshake_type] /= 2;
  315. onionskins_usec_internal[rpl.handshake_type] /= 2;
  316. onionskins_usec_roundtrip[rpl.handshake_type] /= 2;
  317. }
  318. }
  319. }
  320. circ = job->circ;
  321. log_debug(LD_OR,
  322. "Unpacking cpuworker reply %p, circ=%p, success=%d",
  323. job, circ, rpl.success);
  324. if (circ->base_.magic == DEAD_CIRCUIT_MAGIC) {
  325. /* The circuit was supposed to get freed while the reply was
  326. * pending. Instead, it got left for us to free so that we wouldn't freak
  327. * out when the job->circ field wound up pointing to nothing. */
  328. log_debug(LD_OR, "Circuit died while reply was pending. Freeing memory.");
  329. circ->base_.magic = 0;
  330. tor_free(circ);
  331. goto done_processing;
  332. }
  333. circ->workqueue_entry = NULL;
  334. if (TO_CIRCUIT(circ)->marked_for_close) {
  335. /* We already marked this circuit; we can't call it open. */
  336. log_debug(LD_OR,"circuit is already marked.");
  337. goto done_processing;
  338. }
  339. if (rpl.success == 0) {
  340. log_debug(LD_OR,
  341. "decoding onionskin failed. "
  342. "(Old key or bad software.) Closing.");
  343. circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_TORPROTOCOL);
  344. goto done_processing;
  345. }
  346. if (onionskin_answer(circ,
  347. &rpl.created_cell,
  348. (const char*)rpl.keys, sizeof(rpl.keys),
  349. rpl.rend_auth_material) < 0) {
  350. log_warn(LD_OR,"onionskin_answer failed. Closing.");
  351. circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_INTERNAL);
  352. goto done_processing;
  353. }
  354. log_debug(LD_OR,"onionskin_answer succeeded. Yay.");
  355. done_processing:
  356. memwipe(&rpl, 0, sizeof(rpl));
  357. memwipe(job, 0, sizeof(*job));
  358. tor_free(job);
  359. queue_pending_tasks();
  360. }
  361. /** Implementation function for onion handshake requests. */
  362. static workqueue_reply_t
  363. cpuworker_onion_handshake_threadfn(void *state_, void *work_)
  364. {
  365. worker_state_t *state = state_;
  366. cpuworker_job_t *job = work_;
  367. /* variables for onion processing */
  368. server_onion_keys_t *onion_keys = state->onion_keys;
  369. cpuworker_request_t req;
  370. cpuworker_reply_t rpl;
  371. memcpy(&req, &job->u.request, sizeof(req));
  372. tor_assert(req.magic == CPUWORKER_REQUEST_MAGIC);
  373. memset(&rpl, 0, sizeof(rpl));
  374. const create_cell_t *cc = &req.create_cell;
  375. created_cell_t *cell_out = &rpl.created_cell;
  376. struct timeval tv_start = {0,0}, tv_end;
  377. int n;
  378. rpl.timed = req.timed;
  379. rpl.started_at = req.started_at;
  380. rpl.handshake_type = cc->handshake_type;
  381. if (req.timed)
  382. tor_gettimeofday(&tv_start);
  383. n = onion_skin_server_handshake(cc->handshake_type,
  384. cc->onionskin, cc->handshake_len,
  385. onion_keys,
  386. cell_out->reply,
  387. rpl.keys, CPATH_KEY_MATERIAL_LEN,
  388. rpl.rend_auth_material);
  389. if (n < 0) {
  390. /* failure */
  391. log_debug(LD_OR,"onion_skin_server_handshake failed.");
  392. memset(&rpl, 0, sizeof(rpl));
  393. rpl.success = 0;
  394. } else {
  395. /* success */
  396. log_debug(LD_OR,"onion_skin_server_handshake succeeded.");
  397. cell_out->handshake_len = n;
  398. switch (cc->cell_type) {
  399. case CELL_CREATE:
  400. cell_out->cell_type = CELL_CREATED; break;
  401. case CELL_CREATE2:
  402. cell_out->cell_type = CELL_CREATED2; break;
  403. case CELL_CREATE_FAST:
  404. cell_out->cell_type = CELL_CREATED_FAST; break;
  405. default:
  406. tor_assert(0);
  407. return WQ_RPL_SHUTDOWN;
  408. }
  409. rpl.success = 1;
  410. }
  411. rpl.magic = CPUWORKER_REPLY_MAGIC;
  412. if (req.timed) {
  413. struct timeval tv_diff;
  414. int64_t usec;
  415. tor_gettimeofday(&tv_end);
  416. timersub(&tv_end, &tv_start, &tv_diff);
  417. usec = ((int64_t)tv_diff.tv_sec)*1000000 + tv_diff.tv_usec;
  418. if (usec < 0 || usec > MAX_BELIEVABLE_ONIONSKIN_DELAY)
  419. rpl.n_usec = MAX_BELIEVABLE_ONIONSKIN_DELAY;
  420. else
  421. rpl.n_usec = (uint32_t) usec;
  422. }
  423. memcpy(&job->u.reply, &rpl, sizeof(rpl));
  424. memwipe(&req, 0, sizeof(req));
  425. memwipe(&rpl, 0, sizeof(req));
  426. return WQ_RPL_REPLY;
  427. }
  428. /** Take pending tasks from the queue and assign them to cpuworkers. */
  429. static void
  430. queue_pending_tasks(void)
  431. {
  432. or_circuit_t *circ;
  433. create_cell_t *onionskin = NULL;
  434. while (total_pending_tasks < max_pending_tasks) {
  435. circ = onion_next_task(&onionskin);
  436. if (!circ)
  437. return;
  438. if (assign_onionskin_to_cpuworker(circ, onionskin) < 0)
  439. log_info(LD_OR,"assign_to_cpuworker failed. Ignoring.");
  440. }
  441. }
  442. /** DOCDOC */
  443. MOCK_IMPL(workqueue_entry_t *,
  444. cpuworker_queue_work,(workqueue_priority_t priority,
  445. workqueue_reply_t (*fn)(void *, void *),
  446. void (*reply_fn)(void *),
  447. void *arg))
  448. {
  449. tor_assert(threadpool);
  450. return threadpool_queue_work_priority(threadpool,
  451. priority,
  452. fn,
  453. reply_fn,
  454. arg);
  455. }
  456. /** Try to tell a cpuworker to perform the public key operations necessary to
  457. * respond to <b>onionskin</b> for the circuit <b>circ</b>.
  458. *
  459. * Return 0 if we successfully assign the task, or -1 on failure.
  460. */
  461. int
  462. assign_onionskin_to_cpuworker(or_circuit_t *circ,
  463. create_cell_t *onionskin)
  464. {
  465. workqueue_entry_t *queue_entry;
  466. cpuworker_job_t *job;
  467. cpuworker_request_t req;
  468. int should_time;
  469. tor_assert(threadpool);
  470. if (!circ->p_chan) {
  471. log_info(LD_OR,"circ->p_chan gone. Failing circ.");
  472. tor_free(onionskin);
  473. return -1;
  474. }
  475. if (total_pending_tasks >= max_pending_tasks) {
  476. log_debug(LD_OR,"No idle cpuworkers. Queuing.");
  477. if (onion_pending_add(circ, onionskin) < 0) {
  478. tor_free(onionskin);
  479. return -1;
  480. }
  481. return 0;
  482. }
  483. if (!channel_is_client(circ->p_chan))
  484. rep_hist_note_circuit_handshake_assigned(onionskin->handshake_type);
  485. should_time = should_time_request(onionskin->handshake_type);
  486. memset(&req, 0, sizeof(req));
  487. req.magic = CPUWORKER_REQUEST_MAGIC;
  488. req.timed = should_time;
  489. memcpy(&req.create_cell, onionskin, sizeof(create_cell_t));
  490. tor_free(onionskin);
  491. if (should_time)
  492. tor_gettimeofday(&req.started_at);
  493. job = tor_malloc_zero(sizeof(cpuworker_job_t));
  494. job->circ = circ;
  495. memcpy(&job->u.request, &req, sizeof(req));
  496. memwipe(&req, 0, sizeof(req));
  497. ++total_pending_tasks;
  498. queue_entry = threadpool_queue_work_priority(threadpool,
  499. WQ_PRI_HIGH,
  500. cpuworker_onion_handshake_threadfn,
  501. cpuworker_onion_handshake_replyfn,
  502. job);
  503. if (!queue_entry) {
  504. log_warn(LD_BUG, "Couldn't queue work on threadpool");
  505. tor_free(job);
  506. return -1;
  507. }
  508. log_debug(LD_OR, "Queued task %p (qe=%p, circ=%p)",
  509. job, queue_entry, job->circ);
  510. circ->workqueue_entry = queue_entry;
  511. return 0;
  512. }
  513. /** If <b>circ</b> has a pending handshake that hasn't been processed yet,
  514. * remove it from the worker queue. */
  515. void
  516. cpuworker_cancel_circ_handshake(or_circuit_t *circ)
  517. {
  518. cpuworker_job_t *job;
  519. if (circ->workqueue_entry == NULL)
  520. return;
  521. job = workqueue_entry_cancel(circ->workqueue_entry);
  522. if (job) {
  523. /* It successfully cancelled. */
  524. memwipe(job, 0xe0, sizeof(*job));
  525. tor_free(job);
  526. tor_assert(total_pending_tasks > 0);
  527. --total_pending_tasks;
  528. /* if (!job), this is done in cpuworker_onion_handshake_replyfn. */
  529. circ->workqueue_entry = NULL;
  530. }
  531. }