scheduler_kist.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. /* Copyright (c) 2017, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. #include <event2/event.h>
  4. #include <netinet/tcp.h>
  5. #include "or.h"
  6. #include "buffers.h"
  7. #include "config.h"
  8. #include "connection.h"
  9. #include "networkstatus.h"
  10. #define TOR_CHANNEL_INTERNAL_
  11. #include "channel.h"
  12. #include "channeltls.h"
  13. #define SCHEDULER_PRIVATE_
  14. #include "scheduler.h"
  15. #define TLS_PER_CELL_OVERHEAD 29
  16. /* Kernel interface needed for KIST. */
  17. #include <linux/sockios.h>
  18. /*****************************************************************************
  19. * Data structures and supporting functions
  20. *****************************************************************************/
  21. /* Socket_table hash table stuff. The socket_table keeps track of per-socket
  22. * limit information imposed by kist and used by kist. */
  23. static uint32_t
  24. socket_table_ent_hash(const socket_table_ent_t *ent)
  25. {
  26. return (uint32_t)ent->chan->global_identifier;
  27. }
  28. static unsigned
  29. socket_table_ent_eq(const socket_table_ent_t *a, const socket_table_ent_t *b)
  30. {
  31. return a->chan->global_identifier == b->chan->global_identifier;
  32. }
  33. typedef HT_HEAD(socket_table_s, socket_table_ent_s) socket_table_t;
  34. static socket_table_t socket_table = HT_INITIALIZER();
  35. HT_PROTOTYPE(socket_table_s, socket_table_ent_s, node, socket_table_ent_hash,
  36. socket_table_ent_eq)
  37. HT_GENERATE2(socket_table_s, socket_table_ent_s, node, socket_table_ent_hash,
  38. socket_table_ent_eq, 0.6, tor_reallocarray, tor_free_)
  39. /* outbuf_table hash table stuff. The outbuf_table keeps track of which
  40. * channels have data sitting in their outbuf so the kist scheduler can force
  41. * a write from outbuf to kernel periodically during a run and at the end of a
  42. * run. */
  43. typedef struct outbuf_table_ent_s {
  44. HT_ENTRY(outbuf_table_ent_s) node;
  45. channel_t *chan;
  46. } outbuf_table_ent_t;
  47. static uint32_t
  48. outbuf_table_ent_hash(const outbuf_table_ent_t *ent)
  49. {
  50. return (uint32_t)ent->chan->global_identifier;
  51. }
  52. static unsigned
  53. outbuf_table_ent_eq(const outbuf_table_ent_t *a, const outbuf_table_ent_t *b)
  54. {
  55. return a->chan->global_identifier == b->chan->global_identifier;
  56. }
  57. static outbuf_table_t outbuf_table = HT_INITIALIZER();
  58. HT_PROTOTYPE(outbuf_table_s, outbuf_table_ent_s, node, outbuf_table_ent_hash,
  59. outbuf_table_ent_eq)
  60. HT_GENERATE2(outbuf_table_s, outbuf_table_ent_s, node, outbuf_table_ent_hash,
  61. outbuf_table_ent_eq, 0.6, tor_reallocarray, tor_free_)
  62. /*****************************************************************************
  63. * Other internal data
  64. *****************************************************************************/
  65. static struct timeval scheduler_last_run = {0, 0};
  66. static double sock_buf_size_factor = 1.0;
  67. STATIC int32_t sched_run_interval = 10;
  68. static scheduler_t *kist_scheduler = NULL;
  69. /*****************************************************************************
  70. * Internally called function implementations
  71. *****************************************************************************/
  72. /* Little helper function to get the length of a channel's output buffer */
  73. static inline size_t
  74. channel_outbuf_length(channel_t *chan)
  75. {
  76. return buf_datalen(TO_CONN(BASE_CHAN_TO_TLS(chan)->conn)->outbuf);
  77. }
  78. /* Little helper function for HT_FOREACH_FN. */
  79. static int
  80. each_channel_write_to_kernel(outbuf_table_ent_t *ent, void *data)
  81. {
  82. (void) data; /* Make compiler happy. */
  83. channel_write_to_kernel(ent->chan);
  84. return 0; /* Returning non-zero removes the element from the table. */
  85. }
  86. /* Free the given outbuf table entry ent. */
  87. static int
  88. free_outbuf_info_by_ent(outbuf_table_ent_t *ent, void *data)
  89. {
  90. (void) data; /* Make compiler happy. */
  91. log_debug(LD_SCHED, "Freeing outbuf table entry from chan=%" PRIu64,
  92. ent->chan->global_identifier);
  93. tor_free(ent);
  94. return 1; /* So HT_FOREACH_FN will remove the element */
  95. }
  96. /* Clean up outbuf_table. Probably because the KIST sched impl is going away */
  97. static void
  98. free_all_outbuf_info(void)
  99. {
  100. HT_FOREACH_FN(outbuf_table_s, &outbuf_table, free_outbuf_info_by_ent, NULL);
  101. }
  102. /* Free the given socket table entry ent. */
  103. static int
  104. free_socket_info_by_ent(socket_table_ent_t *ent, void *data)
  105. {
  106. (void) data; /* Make compiler happy. */
  107. log_debug(LD_SCHED, "Freeing socket table entry from chan=%" PRIu64,
  108. ent->chan->global_identifier);
  109. tor_free(ent);
  110. return 1; /* So HT_FOREACH_FN will remove the element */
  111. }
  112. /* Clean up socket_table. Probably because the KIST sched impl is going away */
  113. static void
  114. free_all_socket_info(void)
  115. {
  116. HT_FOREACH_FN(socket_table_s, &socket_table, free_socket_info_by_ent, NULL);
  117. }
  118. static socket_table_ent_t *
  119. socket_table_search(socket_table_t *table, const channel_t *chan)
  120. {
  121. socket_table_ent_t search, *ent = NULL;
  122. search.chan = chan;
  123. ent = HT_FIND(socket_table_s, table, &search);
  124. return ent;
  125. }
  126. /* Free a socket entry in table for the given chan. */
  127. static void
  128. free_socket_info_by_chan(socket_table_t *table, const channel_t *chan)
  129. {
  130. socket_table_ent_t *ent = NULL;
  131. ent = socket_table_search(table, chan);
  132. if (!ent)
  133. return;
  134. log_debug(LD_SCHED, "scheduler free socket info for chan=%" PRIu64,
  135. chan->global_identifier);
  136. HT_REMOVE(socket_table_s, table, ent);
  137. free_socket_info_by_ent(ent, NULL);
  138. }
  139. MOCK_IMPL(void,
  140. update_socket_info_impl, (socket_table_ent_t *ent))
  141. {
  142. int64_t tcp_space, extra_space;
  143. const tor_socket_t sock =
  144. TO_CONN(BASE_CHAN_TO_TLS((channel_t *) ent->chan)->conn)->s;
  145. struct tcp_info tcp;
  146. socklen_t tcp_info_len = sizeof(tcp);
  147. /* Gather information */
  148. getsockopt(sock, SOL_TCP, TCP_INFO, (void *)&(tcp), &tcp_info_len);
  149. ioctl(sock, SIOCOUTQNSD, &(ent->notsent));
  150. ent->cwnd = tcp.tcpi_snd_cwnd;
  151. ent->unacked = tcp.tcpi_unacked;
  152. ent->mss = tcp.tcpi_snd_mss;
  153. tcp_space = (ent->cwnd - ent->unacked) * ent->mss;
  154. if (tcp_space < 0) {
  155. tcp_space = 0;
  156. }
  157. extra_space =
  158. clamp_double_to_int64((ent->cwnd * ent->mss) * sock_buf_size_factor) -
  159. ent->notsent;
  160. if (extra_space < 0) {
  161. extra_space = 0;
  162. }
  163. ent->limit = tcp_space + extra_space;
  164. return;
  165. }
  166. /* Given a socket that isn't in the table, add it.
  167. * Given a socket that is in the table, reinit values that need init-ing
  168. * every scheduling run
  169. */
  170. static void
  171. init_socket_info(socket_table_t *table, const channel_t *chan)
  172. {
  173. socket_table_ent_t *ent = NULL;
  174. ent = socket_table_search(table, chan);
  175. if (!ent) {
  176. log_debug(LD_SCHED, "scheduler init socket info for chan=%" PRIu64,
  177. chan->global_identifier);
  178. ent = tor_malloc_zero(sizeof(*ent));
  179. ent->chan = chan;
  180. HT_INSERT(socket_table_s, table, ent);
  181. }
  182. ent->written = 0;
  183. }
  184. /* Add chan to the outbuf table if it isn't already in it. If it is, then don't
  185. * do anything */
  186. static void
  187. outbuf_table_add(outbuf_table_t *table, channel_t *chan)
  188. {
  189. outbuf_table_ent_t search, *ent;
  190. search.chan = chan;
  191. ent = HT_FIND(outbuf_table_s, table, &search);
  192. if (!ent) {
  193. log_debug(LD_SCHED, "scheduler init outbuf info for chan=%" PRIu64,
  194. chan->global_identifier);
  195. ent = tor_malloc_zero(sizeof(*ent));
  196. ent->chan = chan;
  197. HT_INSERT(outbuf_table_s, table, ent);
  198. }
  199. }
  200. static void
  201. outbuf_table_remove(outbuf_table_t *table, channel_t *chan)
  202. {
  203. outbuf_table_ent_t search, *ent;
  204. search.chan = chan;
  205. ent = HT_FIND(outbuf_table_s, table, &search);
  206. if (ent) {
  207. HT_REMOVE(outbuf_table_s, table, ent);
  208. free_outbuf_info_by_ent(ent, NULL);
  209. }
  210. }
  211. /* Set the scheduler running interval. */
  212. static void
  213. set_scheduler_run_interval(const networkstatus_t *ns)
  214. {
  215. int32_t old_sched_run_interval = sched_run_interval;
  216. sched_run_interval = kist_scheduler_run_interval(ns);
  217. if (old_sched_run_interval != sched_run_interval) {
  218. log_info(LD_SCHED, "Scheduler KIST changing its running interval "
  219. "from %" PRId32 " to %" PRId32,
  220. old_sched_run_interval, sched_run_interval);
  221. }
  222. }
  223. /* Return true iff the channel associated socket can write to the kernel that
  224. * is hasn't reach the limit. */
  225. static int
  226. socket_can_write(socket_table_t *table, const channel_t *chan)
  227. {
  228. socket_table_ent_t *ent = NULL;
  229. ent = socket_table_search(table, chan);
  230. tor_assert(ent);
  231. int64_t kist_limit_space =
  232. (int64_t) (ent->limit - ent->written) /
  233. (CELL_MAX_NETWORK_SIZE + TLS_PER_CELL_OVERHEAD);
  234. return kist_limit_space > 0;
  235. }
  236. /* Update the channel's socket kernel information. */
  237. static void
  238. update_socket_info(socket_table_t *table, const channel_t *chan)
  239. {
  240. socket_table_ent_t *ent = NULL;
  241. ent = socket_table_search(table, chan);
  242. tor_assert(ent);
  243. update_socket_info_impl(ent);
  244. }
  245. /* Increament the channel's socket written value by the number of bytes. */
  246. static void
  247. update_socket_written(socket_table_t *table, channel_t *chan, size_t bytes)
  248. {
  249. socket_table_ent_t *ent = NULL;
  250. ent = socket_table_search(table, chan);
  251. tor_assert(ent);
  252. log_debug(LD_SCHED, "chan=%" PRIu64 " wrote %lu bytes, old was %" PRIi64,
  253. chan->global_identifier, bytes, ent->written);
  254. ent->written += bytes;
  255. }
  256. /*
  257. * A naive KIST impl would write every single cell all the way to the kernel.
  258. * That would take a lot of system calls. A less bad KIST impl would write a
  259. * channel's outbuf to the kernel only when we are switching to a different
  260. * channel. But if we have two channels with equal priority, we end up writing
  261. * one cell for each and bouncing back and forth. This KIST impl avoids that
  262. * by only writing a channel's outbuf to the kernel if it has 8 cells or more
  263. * in it.
  264. */
  265. MOCK_IMPL(int, channel_should_write_to_kernel,
  266. (outbuf_table_t *table, channel_t *chan))
  267. {
  268. outbuf_table_add(table, chan);
  269. /* CELL_MAX_NETWORK_SIZE * 8 because we only want to write the outbuf to the
  270. * kernel if there's 8 or more cells waiting */
  271. return channel_outbuf_length(chan) > (CELL_MAX_NETWORK_SIZE * 8);
  272. }
  273. /* Little helper function to write a channel's outbuf all the way to the
  274. * kernel */
  275. MOCK_IMPL(void, channel_write_to_kernel, (channel_t *chan))
  276. {
  277. log_debug(LD_SCHED, "Writing %lu bytes to kernel for chan %" PRIu64,
  278. channel_outbuf_length(chan), chan->global_identifier);
  279. connection_handle_write(TO_CONN(BASE_CHAN_TO_TLS(chan)->conn), 0);
  280. }
  281. /* Return true iff the scheduler has work to perform. */
  282. static int
  283. have_work(void)
  284. {
  285. smartlist_t *cp = get_channels_pending();
  286. tor_assert(cp);
  287. return smartlist_len(cp) > 0;
  288. }
  289. /* Function of the scheduler interface: free_all() */
  290. static void
  291. kist_free_all(void)
  292. {
  293. free_all_outbuf_info();
  294. free_all_socket_info();
  295. }
  296. /* Function of the scheduler interface: on_channel_free() */
  297. static void
  298. kist_on_channel_free(const channel_t *chan)
  299. {
  300. free_socket_info_by_chan(&socket_table, chan);
  301. }
  302. /* Function of the scheduler interface: on_new_consensus() */
  303. static void
  304. kist_scheduler_on_new_consensus(const networkstatus_t *old_c,
  305. const networkstatus_t *new_c)
  306. {
  307. (void) old_c;
  308. (void) new_c;
  309. set_scheduler_run_interval(new_c);
  310. }
  311. /* Function of the scheduler interface: run() */
  312. static void
  313. kist_scheduler_on_new_options(void)
  314. {
  315. sock_buf_size_factor = get_options()->KISTSockBufSizeFactor;
  316. /* Calls kist_scheduler_run_interval which calls get_options(). */
  317. set_scheduler_run_interval(NULL);
  318. }
  319. /* Function of the scheduler interface: init() */
  320. static void
  321. kist_scheduler_init(void)
  322. {
  323. kist_scheduler_on_new_options();
  324. tor_assert(sched_run_interval > 0);
  325. }
  326. /* Function of the scheduler interface: schedule() */
  327. static void
  328. kist_scheduler_schedule(void)
  329. {
  330. struct timeval now, next_run;
  331. int32_t diff;
  332. struct event *ev = get_run_sched_ev();
  333. tor_assert(ev);
  334. if (!have_work()) {
  335. return;
  336. }
  337. tor_gettimeofday(&now);
  338. diff = (int32_t) tv_mdiff(&scheduler_last_run, &now);
  339. if (diff < sched_run_interval) {
  340. next_run.tv_sec = 0;
  341. /* 1000 for ms -> us */
  342. next_run.tv_usec = (sched_run_interval - diff) * 1000;
  343. /* Readding an event reschedules it. It does not duplicate it. */
  344. event_add(ev, &next_run);
  345. } else {
  346. event_active(ev, EV_TIMEOUT, 1);
  347. }
  348. }
  349. /* Function of the scheduler interface: run() */
  350. static void
  351. kist_scheduler_run(void)
  352. {
  353. /* Define variables */
  354. channel_t *chan = NULL; // current working channel
  355. /* The last distinct chan served in a sched loop. */
  356. channel_t *prev_chan = NULL;
  357. int flush_result; // temporarily store results from flush calls
  358. /* Channels to be readding to pending at the end */
  359. smartlist_t *to_readd = NULL;
  360. smartlist_t *cp = get_channels_pending();
  361. /* For each pending channel, collect new kernel information */
  362. SMARTLIST_FOREACH_BEGIN(cp, const channel_t *, pchan) {
  363. init_socket_info(&socket_table, pchan);
  364. update_socket_info(&socket_table, pchan);
  365. } SMARTLIST_FOREACH_END(pchan);
  366. log_debug(LD_SCHED, "Running the scheduler. %d channels pending",
  367. smartlist_len(cp));
  368. /* The main scheduling loop. Loop until there are no more pending channels */
  369. while (smartlist_len(cp) > 0) {
  370. /* get best channel */
  371. chan = smartlist_pqueue_pop(cp, scheduler_compare_channels,
  372. offsetof(channel_t, sched_heap_idx));
  373. tor_assert(chan);
  374. outbuf_table_add(&outbuf_table, chan);
  375. /* if we have switched to a new channel, consider writing the previous
  376. * channel's outbuf to the kernel. */
  377. if (!prev_chan) prev_chan = chan;
  378. if (prev_chan != chan) {
  379. if (channel_should_write_to_kernel(&outbuf_table, prev_chan)) {
  380. channel_write_to_kernel(prev_chan);
  381. outbuf_table_remove(&outbuf_table, prev_chan);
  382. }
  383. prev_chan = chan;
  384. }
  385. /* Only flush and write if the per-socket limit hasn't been hit */
  386. if (socket_can_write(&socket_table, chan)) {
  387. /* flush to channel queue/outbuf */
  388. flush_result = (int)channel_flush_some_cells(chan, 1); // 1 for num cells
  389. /* flush_result has the # cells flushed */
  390. if (flush_result > 0) {
  391. update_socket_written(&socket_table, chan, flush_result *
  392. (CELL_MAX_NETWORK_SIZE + TLS_PER_CELL_OVERHEAD));
  393. }
  394. /* XXX What if we didn't flush? */
  395. }
  396. /* Decide what to do with the channel now */
  397. if (!channel_more_to_flush(chan) &&
  398. !socket_can_write(&socket_table, chan)) {
  399. /* Case 1: no more cells to send, and cannot write */
  400. /*
  401. * You might think we should put the channel in SCHED_CHAN_IDLE. And
  402. * you're probably correct. While implementing KIST, we found that the
  403. * scheduling system would sometimes lose track of channels when we did
  404. * that. We suspect it has to do with the difference between "can't
  405. * write because socket/outbuf is full" and KIST's "can't write because
  406. * we've arbitrarily decided that that's enough for now." Sometimes
  407. * channels run out of cells at the same time they hit their
  408. * kist-imposed write limit and maybe the rest of Tor doesn't put the
  409. * channel back in pending when it is supposed to.
  410. *
  411. * This should be investigated again. It is as simple as changing
  412. * SCHED_CHAN_WAITING_FOR_CELLS to SCHED_CHAN_IDLE and seeing if Tor
  413. * starts having serious throughput issues. Best done in shadow/chutney.
  414. */
  415. chan->scheduler_state = SCHED_CHAN_WAITING_FOR_CELLS;
  416. log_debug(LD_SCHED, "chan=%" PRIu64 " now waiting_for_cells",
  417. chan->global_identifier);
  418. } else if (!channel_more_to_flush(chan)) {
  419. /* Case 2: no more cells to send, but still open for writes */
  420. chan->scheduler_state = SCHED_CHAN_WAITING_FOR_CELLS;
  421. log_debug(LD_SCHED, "chan=%" PRIu64 " now waiting_for_cells",
  422. chan->global_identifier);
  423. } else if (!socket_can_write(&socket_table, chan)) {
  424. /* Case 3: cells to send, but cannot write */
  425. chan->scheduler_state = SCHED_CHAN_WAITING_TO_WRITE;
  426. if (!to_readd)
  427. to_readd = smartlist_new();
  428. smartlist_add(to_readd, chan);
  429. log_debug(LD_SCHED, "chan=%" PRIu64 " now waiting_to_write",
  430. chan->global_identifier);
  431. } else {
  432. /* Case 4: cells to send, and still open for writes */
  433. chan->scheduler_state = SCHED_CHAN_PENDING;
  434. smartlist_pqueue_add(cp, scheduler_compare_channels,
  435. offsetof(channel_t, sched_heap_idx), chan);
  436. }
  437. } /* End of main scheduling loop */
  438. /* Write the outbuf of any channels that still have data */
  439. HT_FOREACH_FN(outbuf_table_s, &outbuf_table, each_channel_write_to_kernel,
  440. NULL);
  441. free_all_outbuf_info();
  442. HT_CLEAR(outbuf_table_s, &outbuf_table);
  443. log_debug(LD_SCHED, "len pending=%d, len to_readd=%d",
  444. smartlist_len(cp),
  445. (to_readd ? smartlist_len(to_readd) : -1));
  446. /* Readd any channels we need to */
  447. if (to_readd) {
  448. SMARTLIST_FOREACH_BEGIN(to_readd, channel_t *, readd_chan) {
  449. readd_chan->scheduler_state = SCHED_CHAN_PENDING;
  450. if (!smartlist_contains(cp, readd_chan)) {
  451. smartlist_pqueue_add(cp, scheduler_compare_channels,
  452. offsetof(channel_t, sched_heap_idx), readd_chan);
  453. }
  454. } SMARTLIST_FOREACH_END(readd_chan);
  455. smartlist_free(to_readd);
  456. }
  457. tor_gettimeofday(&scheduler_last_run);
  458. }
  459. /*****************************************************************************
  460. * Externally called function implementations not called through scheduler_t
  461. *****************************************************************************/
  462. /* Return the KIST scheduler object. If it didn't exists, return a newly
  463. * allocated one but init() is not called. */
  464. scheduler_t *
  465. get_kist_scheduler(void)
  466. {
  467. if (!kist_scheduler) {
  468. log_debug(LD_SCHED, "Allocating kist scheduler struct");
  469. kist_scheduler = tor_malloc_zero(sizeof(*kist_scheduler));
  470. kist_scheduler->free_all = kist_free_all;
  471. kist_scheduler->on_channel_free = kist_on_channel_free;
  472. kist_scheduler->init = kist_scheduler_init;
  473. kist_scheduler->on_new_consensus = kist_scheduler_on_new_consensus;
  474. kist_scheduler->schedule = kist_scheduler_schedule;
  475. kist_scheduler->run = kist_scheduler_run;
  476. kist_scheduler->on_new_options = kist_scheduler_on_new_options;
  477. }
  478. return kist_scheduler;
  479. }
  480. /* Default interval that KIST runs (in ms). */
  481. #define KIST_SCHED_RUN_INTERVAL_DEFAULT 10
  482. /* Minimum interval that KIST runs. This value disables KIST. */
  483. #define KIST_SCHED_RUN_INTERVAL_MIN 0
  484. /* Maximum interval that KIST runs (in ms). */
  485. #define KIST_SCHED_RUN_INTERVAL_MAX 100
  486. /* Check the torrc for the configured KIST scheduler run frequency.
  487. * - If torrc < 0, then return the negative torrc value (shouldn't even be
  488. * using KIST)
  489. * - If torrc > 0, then return the positive torrc value (should use KIST, and
  490. * should use the set value)
  491. * - If torrc == 0, then look in the consensus for what the value should be.
  492. * - If == 0, then return -1 (don't use KIST)
  493. * - If > 0, then return the positive consensus value
  494. * - If consensus doesn't say anything, return 10 milliseconds
  495. */
  496. int32_t
  497. kist_scheduler_run_interval(const networkstatus_t *ns)
  498. {
  499. int32_t run_interval = (int32_t)get_options()->KISTSchedRunInterval;
  500. if (run_interval != 0) {
  501. log_debug(LD_SCHED, "Found KISTSchedRunInterval in torrc. Using that.");
  502. return run_interval;
  503. }
  504. log_debug(LD_SCHED, "Turning to the consensus for KISTSchedRunInterval");
  505. run_interval = networkstatus_get_param(ns, "KISTSchedRunInterval",
  506. KIST_SCHED_RUN_INTERVAL_DEFAULT,
  507. KIST_SCHED_RUN_INTERVAL_MIN,
  508. KIST_SCHED_RUN_INTERVAL_MAX);
  509. if (run_interval <= 0)
  510. return -1;
  511. return run_interval;
  512. }