GNUnet  0.10.x
Data Structures | Macros | Enumerations | Functions | Variables
testbed_api_operations.c File Reference

functions to manage operation queues More...

#include "platform.h"
#include "testbed_api_operations.h"
#include "testbed_api_sd.h"
Include dependency graph for testbed_api_operations.c:

Go to the source code of this file.

Data Structures

struct  QueueEntry
 An entry in the operation queue. More...
 
struct  TimeSlot
 A slot to record time taken by an operation. More...
 
struct  FeedbackCtx
 Context for operation queues of type OPERATION_QUEUE_TYPE_ADAPTIVE. More...
 
struct  OperationQueue
 Queue of operations where we can only support a certain number of concurrent operations of a particular type. More...
 
struct  ReadyQueueEntry
 An entry in the ready queue (implemented as DLL) More...
 
struct  GNUNET_TESTBED_Operation
 Opaque handle to an abstract operation to be executed by the testing framework. More...
 

Macros

#define ADAPTIVE_QUEUE_DEFAULT_HISTORY   40
 The number of readings containing past operation's timing information that we keep track of for adaptive queues. More...
 
#define ADAPTIVE_QUEUE_DEFAULT_MAX_ACTIVE   4
 The number of parallel opeartions we start with by default for adaptive queues. More...
 

Enumerations

enum  OperationState {
  OP_STATE_INIT, OP_STATE_WAITING, OP_STATE_READY, OP_STATE_ACTIVE,
  OP_STATE_INACTIVE
}
 Operation state. More...
 

Functions

static void assign_timeslot (struct GNUNET_TESTBED_Operation *op, struct OperationQueue *queue)
 Assigns the given operation a time slot from the given operation queue. More...
 
static void remove_queue_entry (struct GNUNET_TESTBED_Operation *op, unsigned int index)
 Removes a queue entry of an operation from one of the operation queues' lists depending on the state of the operation. More...
 
static void change_state (struct GNUNET_TESTBED_Operation *op, enum OperationState state)
 Changes the state of the operation while moving its associated queue entries in the operation's operation queues. More...
 
static void rq_remove (struct GNUNET_TESTBED_Operation *op)
 Removes an operation from the ready queue. More...
 
static void process_rq_task (void *cls)
 Processes the ready queue by calling the operation start callback of the operation at the head. More...
 
static void rq_add (struct GNUNET_TESTBED_Operation *op)
 Adds the operation to the ready queue and starts the 'process_rq_task'. More...
 
static int is_queue_empty (struct OperationQueue *opq)
 Checks if the given operation queue is empty or not. More...
 
static int decide_capacity (struct OperationQueue *opq, struct QueueEntry *entry, struct GNUNET_TESTBED_Operation ***ops_, unsigned int *n_ops_)
 Checks if the given operation queue has enough resources to provide for the operation of the given queue entry. More...
 
static void merge_ops (struct GNUNET_TESTBED_Operation ***old, unsigned int *n_old, struct GNUNET_TESTBED_Operation **new, unsigned int n_new)
 Merges an array of operations into another, eliminating duplicates. More...
 
static int check_readiness (struct GNUNET_TESTBED_Operation *op)
 Checks for the readiness of an operation and schedules a operation start task. More...
 
static void defer (struct GNUNET_TESTBED_Operation *op)
 Defers a ready to be executed operation back to waiting. More...
 
static void cleanup_tslots (struct OperationQueue *queue)
 Cleanups the array of timeslots of an operation queue. More...
 
static void adaptive_queue_set_max_active (struct OperationQueue *queue, unsigned int n)
 Cleansup the existing timing slots and sets new timing slots in the given queue to accommodate given number of max active operations. More...
 
static void adapt_parallelism (struct OperationQueue *queue)
 Adapts parallelism in an adaptive queue by using the statistical data from the feedback context. More...
 
static void update_tslots (struct GNUNET_TESTBED_Operation *op)
 update tslots with the operation's completion time. More...
 
struct GNUNET_TESTBED_OperationGNUNET_TESTBED_operation_create_ (void *cls, OperationStart start, OperationRelease release)
 Create an 'operation' to be performed. More...
 
struct OperationQueueGNUNET_TESTBED_operation_queue_create_ (enum OperationQueueType type, unsigned int max_active)
 Create an operation queue. More...
 
static void queue_destroy (struct OperationQueue *queue)
 Cleanup the given operation queue. More...
 
void GNUNET_TESTBED_operation_queue_destroy_ (struct OperationQueue *queue)
 Destroys an operation queue. More...
 
int GNUNET_TESTBED_operation_queue_destroy_empty_ (struct OperationQueue *queue)
 Destroys the operation queue if it is empty. More...
 
static void recheck_waiting (struct OperationQueue *opq)
 Rechecks if any of the operations in the given operation queue's waiting list can be made active. More...
 
void GNUNET_TESTBED_operation_queue_reset_max_active_ (struct OperationQueue *queue, unsigned int max_active)
 Function to reset the maximum number of operations in the given queue. More...
 
void GNUNET_TESTBED_operation_queue_insert2_ (struct OperationQueue *queue, struct GNUNET_TESTBED_Operation *op, unsigned int nres)
 Add an operation to a queue. More...
 
void GNUNET_TESTBED_operation_queue_insert_ (struct OperationQueue *queue, struct GNUNET_TESTBED_Operation *op)
 Add an operation to a queue. More...
 
void GNUNET_TESTBED_operation_begin_wait_ (struct GNUNET_TESTBED_Operation *op)
 Marks the given operation as waiting on the queues. More...
 
void GNUNET_TESTBED_operation_inactivate_ (struct GNUNET_TESTBED_Operation *op)
 Marks an active operation as inactive - the operation will be kept in a ready-to-be-released state and continues to hold resources until another operation contents for them. More...
 
void GNUNET_TESTBED_operation_activate_ (struct GNUNET_TESTBED_Operation *op)
 Marks and inactive operation as active. More...
 
void GNUNET_TESTBED_operation_release_ (struct GNUNET_TESTBED_Operation *op)
 An operation is 'done' (was cancelled or finished); remove it from the queues and release associated resources. More...
 
void GNUNET_TESTBED_operation_mark_failed (struct GNUNET_TESTBED_Operation *op)
 Marks an operation as failed. More...
 
void __attribute__ ((destructor))
 Cleanup expired operation queues. More...
 

Variables

static struct ReadyQueueEntryrq_head
 DLL head for the ready queue. More...
 
static struct ReadyQueueEntryrq_tail
 DLL tail for the ready queue. More...
 
static struct OperationQueue ** expired_opqs
 Array of operation queues which are to be destroyed. More...
 
static unsigned int n_expired_opqs
 Number of expired operation queues in the above array. More...
 
struct GNUNET_SCHEDULER_Taskprocess_rq_task_id
 The id of the task to process the ready queue. More...
 

Detailed Description

functions to manage operation queues

Author
Christian Grothoff
Sree Harsha Totakura

Definition in file testbed_api_operations.c.

Macro Definition Documentation

◆ ADAPTIVE_QUEUE_DEFAULT_HISTORY

#define ADAPTIVE_QUEUE_DEFAULT_HISTORY   40

The number of readings containing past operation's timing information that we keep track of for adaptive queues.

Definition at line 36 of file testbed_api_operations.c.

Referenced by GNUNET_TESTBED_operation_queue_create_().

◆ ADAPTIVE_QUEUE_DEFAULT_MAX_ACTIVE

#define ADAPTIVE_QUEUE_DEFAULT_MAX_ACTIVE   4

The number of parallel opeartions we start with by default for adaptive queues.

Definition at line 42 of file testbed_api_operations.c.

Referenced by adapt_parallelism(), and GNUNET_TESTBED_operation_queue_create_().

Enumeration Type Documentation

◆ OperationState

Operation state.

Enumerator
OP_STATE_INIT 

The operation is just created and is in initial state.

OP_STATE_WAITING 

The operation is currently waiting for resources.

OP_STATE_READY 

The operation is ready to be started.

OP_STATE_ACTIVE 

The operation has started and is active.

OP_STATE_INACTIVE 

The operation is inactive.

It still holds resources on the operation queues. However, this operation will be evicted when another operation requires resources from the maxed out queues this operation is holding resources from.

Definition at line 250 of file testbed_api_operations.c.

251 {
256 
261 
266 
271 
279 };
The operation is inactive.
The operation is just created and is in initial state.
The operation is currently waiting for resources.
The operation is ready to be started.
The operation has started and is active.

Function Documentation

◆ assign_timeslot()

static void assign_timeslot ( struct GNUNET_TESTBED_Operation op,
struct OperationQueue queue 
)
static

Assigns the given operation a time slot from the given operation queue.

Parameters
opthe operation
queuethe operation queue
Returns
the timeslot

Definition at line 414 of file testbed_api_operations.c.

References FeedbackCtx::alloc_head, FeedbackCtx::alloc_tail, OperationQueue::fctx, GNUNET_assert, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_CONTAINER_DLL_remove, QueueEntry::op, TimeSlot::op, OPERATION_QUEUE_TYPE_ADAPTIVE, GNUNET_TESTBED_Operation::tslots_head, GNUNET_TESTBED_Operation::tslots_tail, and OperationQueue::type.

Referenced by process_rq_task().

416 {
417  struct FeedbackCtx *fctx = queue->fctx;
418  struct TimeSlot *tslot;
419 
421  tslot = fctx->alloc_head;
422  GNUNET_assert (NULL != tslot);
423  GNUNET_CONTAINER_DLL_remove (fctx->alloc_head, fctx->alloc_tail, tslot);
425  tslot->op = op;
426 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct TimeSlot * tslots_head
Head pointer for DLL of tslots allocated to this operation.
Context for operation queues of type OPERATION_QUEUE_TYPE_ADAPTIVE.
struct TimeSlot * alloc_head
Head for DLL of time slots which are free to be allocated to operations.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
struct TimeSlot * tslots_tail
Tail pointer for DLL of tslots allocated to this operation.
enum OperationQueueType type
The type of this opeartion queue.
struct TimeSlot * alloc_tail
Tail for DLL of time slots which are free to be allocated to operations.
A slot to record time taken by an operation.
struct GNUNET_TESTBED_Operation * op
The operation to which this timeslot is currently allocated to.
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:139
struct FeedbackCtx * fctx
Feedback context; only relevant for adaptive operation queues.
Operation queue which adapts the number of operations to be active based on the operation completion ...
Here is the caller graph for this function:

◆ remove_queue_entry()

static void remove_queue_entry ( struct GNUNET_TESTBED_Operation op,
unsigned int  index 
)
static

Removes a queue entry of an operation from one of the operation queues' lists depending on the state of the operation.

Parameters
opthe operation whose entry has to be removed
indexthe index of the entry in the operation's array of queue entries

Definition at line 437 of file testbed_api_operations.c.

References OperationQueue::aq_head, OperationQueue::aq_tail, GNUNET_assert, GNUNET_CONTAINER_DLL_remove, OperationQueue::nq_head, OperationQueue::nq_tail, OP_STATE_ACTIVE, OP_STATE_INACTIVE, OP_STATE_INIT, OP_STATE_READY, OP_STATE_WAITING, GNUNET_TESTBED_Operation::qentries, GNUNET_TESTBED_Operation::queues, OperationQueue::rq_head, OperationQueue::rq_tail, GNUNET_TESTBED_Operation::state, OperationQueue::wq_head, and OperationQueue::wq_tail.

Referenced by change_state(), and GNUNET_TESTBED_operation_release_().

438 {
439  struct OperationQueue *opq;
440  struct QueueEntry *entry;
441 
442  opq = op->queues[index];
443  entry = op->qentries[index];
444  switch (op->state)
445  {
446  case OP_STATE_INIT:
447  GNUNET_assert (0);
448  break;
449  case OP_STATE_WAITING:
450  GNUNET_CONTAINER_DLL_remove (opq->wq_head, opq->wq_tail, entry);
451  break;
452  case OP_STATE_READY:
453  GNUNET_CONTAINER_DLL_remove (opq->rq_head, opq->rq_tail, entry);
454  break;
455  case OP_STATE_ACTIVE:
456  GNUNET_CONTAINER_DLL_remove (opq->aq_head, opq->aq_tail, entry);
457  break;
458  case OP_STATE_INACTIVE:
459  GNUNET_CONTAINER_DLL_remove (opq->nq_head, opq->nq_tail, entry);
460  break;
461  }
462 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct QueueEntry * aq_head
DLL head for the active queue.
struct QueueEntry * rq_tail
DLL tail for the ready queue.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
The operation is inactive.
struct QueueEntry ** qentries
Array of operation queue entries corresponding to this operation in operation queues for this operati...
struct QueueEntry * nq_head
DLL head for the inactive queue.
The operation is just created and is in initial state.
struct QueueEntry * rq_head
DLL head for the ready queue.
The operation is currently waiting for resources.
struct QueueEntry * wq_tail
DLL tail for the wait queue.
The operation is ready to be started.
An entry in the operation queue.
enum OperationState state
The state of the operation.
Queue of operations where we can only support a certain number of concurrent operations of a particul...
struct OperationQueue ** queues
Array of operation queues this Operation belongs to.
struct QueueEntry * aq_tail
DLL tail for the active queue.
struct QueueEntry * nq_tail
DLL tail for the inactive queue.
The operation has started and is active.
struct QueueEntry * wq_head
DLL head for the wait queue.
Here is the caller graph for this function:

◆ change_state()

static void change_state ( struct GNUNET_TESTBED_Operation op,
enum OperationState  state 
)
static

Changes the state of the operation while moving its associated queue entries in the operation's operation queues.

Parameters
opthe operation whose state has to be changed
statethe state the operation should have. It cannot be OP_STATE_INIT

Definition at line 473 of file testbed_api_operations.c.

References OperationQueue::aq_head, OperationQueue::aq_tail, GNUNET_array_append, GNUNET_assert, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_new, OperationQueue::nq_head, OperationQueue::nq_tail, GNUNET_TESTBED_Operation::nqueues, QueueEntry::nres, GNUNET_TESTBED_Operation::nres, QueueEntry::op, OP_STATE_ACTIVE, OP_STATE_INACTIVE, OP_STATE_INIT, OP_STATE_READY, OP_STATE_WAITING, GNUNET_TESTBED_Operation::qentries, GNUNET_TESTBED_Operation::queues, remove_queue_entry(), OperationQueue::rq_head, OperationQueue::rq_tail, state, GNUNET_TESTBED_Operation::state, OperationQueue::wq_head, and OperationQueue::wq_tail.

Referenced by check_readiness(), defer(), GNUNET_TESTBED_operation_activate_(), GNUNET_TESTBED_operation_begin_wait_(), GNUNET_TESTBED_operation_inactivate_(), and process_rq_task().

474 {
475  struct QueueEntry *entry;
476  struct OperationQueue *opq;
477  unsigned int cnt;
478  unsigned int s;
479 
481  GNUNET_assert (NULL != op->queues);
482  GNUNET_assert (NULL != op->nres);
483  GNUNET_assert ((OP_STATE_INIT == op->state) || (NULL != op->qentries));
484  GNUNET_assert (op->state != state);
485  for (cnt = 0; cnt < op->nqueues; cnt++)
486  {
487  if (OP_STATE_INIT == op->state)
488  {
489  entry = GNUNET_new (struct QueueEntry);
490  entry->op = op;
491  entry->nres = op->nres[cnt];
492  s = cnt;
493  GNUNET_array_append (op->qentries, s, entry);
494  }
495  else
496  {
497  entry = op->qentries[cnt];
498  remove_queue_entry (op, cnt);
499  }
500  opq = op->queues[cnt];
501  switch (state)
502  {
503  case OP_STATE_INIT:
504  GNUNET_assert (0);
505  break;
506  case OP_STATE_WAITING:
508  break;
509  case OP_STATE_READY:
511  break;
512  case OP_STATE_ACTIVE:
514  break;
515  case OP_STATE_INACTIVE:
517  break;
518  }
519  }
520  op->state = state;
521 }
unsigned int * nres
Array of number of resources an operation need from each queue.
struct QueueEntry * aq_head
DLL head for the active queue.
unsigned int nres
How many units of resources does the operation need.
struct QueueEntry * rq_tail
DLL tail for the ready queue.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
The operation is inactive.
struct QueueEntry ** qentries
Array of operation queue entries corresponding to this operation in operation queues for this operati...
struct QueueEntry * nq_head
DLL head for the inactive queue.
The operation is just created and is in initial state.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
unsigned int nqueues
Number of queues in the operation queues array.
enum State state
current state of profiling
struct QueueEntry * rq_head
DLL head for the ready queue.
The operation is currently waiting for resources.
struct QueueEntry * wq_tail
DLL tail for the wait queue.
The operation is ready to be started.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
static void remove_queue_entry(struct GNUNET_TESTBED_Operation *op, unsigned int index)
Removes a queue entry of an operation from one of the operation queues&#39; lists depending on the state ...
An entry in the operation queue.
#define GNUNET_array_append(arr, size, element)
Append an element to a list (growing the list by one).
enum OperationState state
The state of the operation.
Queue of operations where we can only support a certain number of concurrent operations of a particul...
struct OperationQueue ** queues
Array of operation queues this Operation belongs to.
struct QueueEntry * aq_tail
DLL tail for the active queue.
struct QueueEntry * nq_tail
DLL tail for the inactive queue.
The operation has started and is active.
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:139
struct QueueEntry * wq_head
DLL head for the wait queue.
struct GNUNET_TESTBED_Operation * op
The operation this entry holds.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rq_remove()

static void rq_remove ( struct GNUNET_TESTBED_Operation op)
static

Removes an operation from the ready queue.

Also stops the 'process_rq_task' if the given operation is the last one in the queue.

Parameters
opthe operation to be removed

Definition at line 531 of file testbed_api_operations.c.

References GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_SCHEDULER_cancel(), and GNUNET_TESTBED_Operation::rq_entry.

Referenced by defer(), GNUNET_TESTBED_operation_release_(), and process_rq_task().

532 {
533  GNUNET_assert (NULL != op->rq_entry);
535  GNUNET_free (op->rq_entry);
536  op->rq_entry = NULL;
537  if ( (NULL == rq_head) && (NULL != process_rq_task_id) )
538  {
540  process_rq_task_id = NULL;
541  }
542 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct ReadyQueueEntry * rq_head
DLL head for the ready queue.
struct GNUNET_SCHEDULER_Task * process_rq_task_id
The id of the task to process the ready queue.
struct ReadyQueueEntry * rq_entry
Entry corresponding to this operation in ready queue.
static struct ReadyQueueEntry * rq_tail
DLL tail for the ready queue.
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_rq_task()

static void process_rq_task ( void *  cls)
static

Processes the ready queue by calling the operation start callback of the operation at the head.

The operation is then removed from the queue. The task is scheduled to run again immediately until no more operations are in the ready queue.

Parameters
clsNULL

Definition at line 554 of file testbed_api_operations.c.

References assign_timeslot(), GNUNET_TESTBED_Operation::cb_cls, change_state(), GNUNET_assert, GNUNET_SCHEDULER_add_now(), GNUNET_TIME_absolute_get(), GNUNET_TESTBED_Operation::nqueues, QueueEntry::op, ReadyQueueEntry::op, OP_STATE_ACTIVE, OPERATION_QUEUE_TYPE_ADAPTIVE, QueueEntry::queue, GNUNET_TESTBED_Operation::queues, rq_remove(), GNUNET_TESTBED_Operation::start, GNUNET_TESTBED_Operation::tstart, and OperationQueue::type.

Referenced by rq_add().

555 {
557  struct OperationQueue *queue;
558  unsigned int cnt;
559 
560  process_rq_task_id = NULL;
561  GNUNET_assert (NULL != rq_head);
562  GNUNET_assert (NULL != (op = rq_head->op));
563  rq_remove (op);
564  if (NULL != rq_head)
567  for (cnt = 0; cnt < op->nqueues; cnt++)
568  {
569  queue = op->queues[cnt];
570  if (OPERATION_QUEUE_TYPE_ADAPTIVE == queue->type)
571  assign_timeslot (op, queue);
572  }
574  if (NULL != op->start)
575  op->start (op->cb_cls);
576 }
static void process_rq_task(void *cls)
Processes the ready queue by calling the operation start callback of the operation at the head...
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
void * cb_cls
Closure for callbacks.
struct GNUNET_TESTBED_Operation * op
The operation associated with this entry.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static void change_state(struct GNUNET_TESTBED_Operation *op, enum OperationState state)
Changes the state of the operation while moving its associated queue entries in the operation&#39;s opera...
static struct ReadyQueueEntry * rq_head
DLL head for the ready queue.
struct GNUNET_SCHEDULER_Task * process_rq_task_id
The id of the task to process the ready queue.
unsigned int nqueues
Number of queues in the operation queues array.
Opaque handle to an abstract operation to be executed by the testing framework.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1273
struct GNUNET_TIME_Absolute tstart
The time at which the operation is started.
static void rq_remove(struct GNUNET_TESTBED_Operation *op)
Removes an operation from the ready queue.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
enum OperationQueueType type
The type of this opeartion queue.
Queue of operations where we can only support a certain number of concurrent operations of a particul...
struct OperationQueue ** queues
Array of operation queues this Operation belongs to.
The operation has started and is active.
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:139
OperationStart start
Function to call when we have the resources to begin the operation.
static void assign_timeslot(struct GNUNET_TESTBED_Operation *op, struct OperationQueue *queue)
Assigns the given operation a time slot from the given operation queue.
Operation queue which adapts the number of operations to be active based on the operation completion ...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rq_add()

static void rq_add ( struct GNUNET_TESTBED_Operation op)
static

Adds the operation to the ready queue and starts the 'process_rq_task'.

Parameters
opthe operation to be queued

Definition at line 585 of file testbed_api_operations.c.

References GNUNET_assert, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_new, GNUNET_SCHEDULER_add_now(), QueueEntry::op, ReadyQueueEntry::op, process_rq_task(), and GNUNET_TESTBED_Operation::rq_entry.

Referenced by check_readiness().

586 {
587  struct ReadyQueueEntry *rq_entry;
588 
589  GNUNET_assert (NULL == op->rq_entry);
590  rq_entry = GNUNET_new (struct ReadyQueueEntry);
591  rq_entry->op = op;
593  op->rq_entry = rq_entry;
594  if (NULL == process_rq_task_id)
596 }
static void process_rq_task(void *cls)
Processes the ready queue by calling the operation start callback of the operation at the head...
struct GNUNET_TESTBED_Operation * op
The operation associated with this entry.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct ReadyQueueEntry * rq_head
DLL head for the ready queue.
struct GNUNET_SCHEDULER_Task * process_rq_task_id
The id of the task to process the ready queue.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1273
struct ReadyQueueEntry * rq_entry
Entry corresponding to this operation in ready queue.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
An entry in the ready queue (implemented as DLL)
static struct ReadyQueueEntry * rq_tail
DLL tail for the ready queue.
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:139
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_queue_empty()

static int is_queue_empty ( struct OperationQueue opq)
static

Checks if the given operation queue is empty or not.

Parameters
opqthe operation queue
Returns
GNUNET_YES if the given operation queue has no operations; GNUNET_NO otherwise

Definition at line 607 of file testbed_api_operations.c.

References OperationQueue::aq_head, GNUNET_NO, GNUNET_YES, OperationQueue::nq_head, OperationQueue::rq_head, and OperationQueue::wq_head.

Referenced by __attribute__(), GNUNET_TESTBED_operation_queue_destroy_(), and GNUNET_TESTBED_operation_queue_destroy_empty_().

608 {
609  if ( (NULL != opq->wq_head)
610  || (NULL != opq->rq_head)
611  || (NULL != opq->aq_head)
612  || (NULL != opq->nq_head) )
613  return GNUNET_NO;
614  return GNUNET_YES;
615 }
struct QueueEntry * aq_head
DLL head for the active queue.
struct QueueEntry * nq_head
DLL head for the inactive queue.
#define GNUNET_NO
Definition: gnunet_common.h:81
struct QueueEntry * rq_head
DLL head for the ready queue.
#define GNUNET_YES
Definition: gnunet_common.h:80
struct QueueEntry * wq_head
DLL head for the wait queue.
Here is the caller graph for this function:

◆ decide_capacity()

static int decide_capacity ( struct OperationQueue opq,
struct QueueEntry entry,
struct GNUNET_TESTBED_Operation ***  ops_,
unsigned int *  n_ops_ 
)
static

Checks if the given operation queue has enough resources to provide for the operation of the given queue entry.

It also checks if any inactive operations are to be released in order to accommodate the needed resources and returns them as an array.

Parameters
opqthe operation queue to check for resource accommodation
entrythe operation queue entry whose operation's resources are to be accommodated
ops_pointer to return the array of operations which are to be released in order to accommodate the new operation. Can be NULL
n_ops_the number of operations in ops_
Returns
GNUNET_YES if the given entry's operation can be accommodated in this queue. GNUNET_NO if it cannot be accommodated; ops_ and n_ops_ will be set to NULL and 0 respectively.

Definition at line 635 of file testbed_api_operations.c.

References OperationQueue::active, OperationQueue::fctx, GNUNET_array_append, GNUNET_assert, GNUNET_free, GNUNET_free_non_null, GNUNET_NO, GNUNET_YES, OperationQueue::max_active, QueueEntry::next, OperationQueue::nq_head, QueueEntry::nres, QueueEntry::op, OPERATION_QUEUE_TYPE_ADAPTIVE, OperationQueue::overload, ret, and OperationQueue::type.

Referenced by check_readiness().

639 {
640  struct QueueEntry **evict_entries;
641  struct GNUNET_TESTBED_Operation **ops;
643  unsigned int n_ops;
644  unsigned int n_evict_entries;
645  unsigned int need;
646  unsigned int max;
647  int deficit;
648  int rval;
649 
650  GNUNET_assert (NULL != (op = entry->op));
651  GNUNET_assert (0 < (need = entry->nres));
652  ops = NULL;
653  n_ops = 0;
654  evict_entries = NULL;
655  n_evict_entries = 0;
656  rval = GNUNET_YES;
658  {
659  GNUNET_assert (NULL != opq->fctx);
660  GNUNET_assert (opq->max_active >= opq->overload);
661  max = opq->max_active - opq->overload;
662  }
663  else
664  max = opq->max_active;
665  if (opq->active > max)
666  {
667  rval = GNUNET_NO;
668  goto ret;
669  }
670  if ((opq->active + need) <= max)
671  goto ret;
672  deficit = need - (max - opq->active);
673  for (entry = opq->nq_head;
674  (0 < deficit) && (NULL != entry);
675  entry = entry->next)
676  {
677  GNUNET_array_append (evict_entries, n_evict_entries, entry);
678  deficit -= entry->nres;
679  }
680  if (0 < deficit)
681  {
682  rval = GNUNET_NO;
683  goto ret;
684  }
685  for (n_ops = 0; n_ops < n_evict_entries;)
686  {
687  op = evict_entries[n_ops]->op;
688  GNUNET_array_append (ops, n_ops, op); /* increments n-ops */
689  }
690 
691  ret:
692  GNUNET_free_non_null (evict_entries);
693  if (NULL != ops_)
694  *ops_ = ops;
695  else
696  GNUNET_free (ops);
697  if (NULL != n_ops_)
698  *n_ops_ = n_ops;
699  return rval;
700 }
unsigned int nres
How many units of resources does the operation need.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct QueueEntry * nq_head
DLL head for the inactive queue.
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
static int ret
Final status code.
Definition: gnunet-arm.c:89
Opaque handle to an abstract operation to be executed by the testing framework.
struct QueueEntry * next
The next DLL pointer.
unsigned int overload
The number of resources occupied by failed operations in the current shot.
enum OperationQueueType type
The type of this opeartion queue.
An entry in the operation queue.
unsigned int active
Number of operations that are currently active in this queue.
#define GNUNET_array_append(arr, size, element)
Append an element to a list (growing the list by one).
unsigned int max_active
Max number of operations which can be active at any time in this queue.
#define GNUNET_YES
Definition: gnunet_common.h:80
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:139
struct FeedbackCtx * fctx
Feedback context; only relevant for adaptive operation queues.
Operation queue which adapts the number of operations to be active based on the operation completion ...
struct GNUNET_TESTBED_Operation * op
The operation this entry holds.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function:

◆ merge_ops()

static void merge_ops ( struct GNUNET_TESTBED_Operation ***  old,
unsigned int *  n_old,
struct GNUNET_TESTBED_Operation **  new,
unsigned int  n_new 
)
static

Merges an array of operations into another, eliminating duplicates.

No ordering is guaranteed.

Parameters
oldthe array into which the merging is done.
n_oldthe number of operations in old array
newthe array from which operations are to be merged
n_newthe number of operations in new array

Definition at line 713 of file testbed_api_operations.c.

References GNUNET_array_append, and GNUNET_assert.

Referenced by check_readiness().

717 {
718  struct GNUNET_TESTBED_Operation **cur;
719  unsigned int i;
720  unsigned int j;
721  unsigned int n_cur;
722 
723  GNUNET_assert (NULL != old);
724  n_cur = *n_old;
725  cur = *old;
726  for (i = 0; i < n_new; i++)
727  {
728  for (j = 0; j < *n_old; j++)
729  {
730  if (new[i] == cur[j])
731  break;
732  }
733  if (j < *n_old)
734  continue;
735  GNUNET_array_append (cur, n_cur, new[j]);
736  }
737  *old = cur;
738  *n_old = n_cur;
739 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Opaque handle to an abstract operation to be executed by the testing framework.
#define GNUNET_array_append(arr, size, element)
Append an element to a list (growing the list by one).
Here is the caller graph for this function:

◆ check_readiness()

static int check_readiness ( struct GNUNET_TESTBED_Operation op)
static

Checks for the readiness of an operation and schedules a operation start task.

Parameters
opthe operation

Definition at line 749 of file testbed_api_operations.c.

References OperationQueue::active, change_state(), decide_capacity(), GNUNET_assert, GNUNET_free, GNUNET_free_non_null, GNUNET_NO, GNUNET_TESTBED_operation_release_(), GNUNET_YES, merge_ops(), GNUNET_TESTBED_Operation::nqueues, GNUNET_TESTBED_Operation::nres, OP_STATE_READY, OP_STATE_WAITING, GNUNET_TESTBED_Operation::qentries, GNUNET_TESTBED_Operation::queues, rq_add(), GNUNET_TESTBED_Operation::rq_entry, and GNUNET_TESTBED_Operation::state.

Referenced by GNUNET_TESTBED_operation_begin_wait_(), and recheck_waiting().

750 {
751  struct GNUNET_TESTBED_Operation **evict_ops;
752  struct GNUNET_TESTBED_Operation **ops;
753  unsigned int n_ops;
754  unsigned int n_evict_ops;
755  unsigned int i;
756 
757  GNUNET_assert (NULL == op->rq_entry);
759  evict_ops = NULL;
760  n_evict_ops = 0;
761  for (i = 0; i < op->nqueues; i++)
762  {
763  ops = NULL;
764  n_ops = 0;
765  if (GNUNET_NO == decide_capacity (op->queues[i], op->qentries[i],
766  &ops, &n_ops))
767  {
768  GNUNET_free_non_null (evict_ops);
769  return GNUNET_NO;
770  }
771  if (NULL == ops)
772  continue;
773  merge_ops (&evict_ops, &n_evict_ops, ops, n_ops);
774  GNUNET_free (ops);
775  }
776  if (NULL != evict_ops)
777  {
778  for (i = 0; i < n_evict_ops; i++)
779  GNUNET_TESTBED_operation_release_ (evict_ops[i]);
780  GNUNET_free (evict_ops);
781  evict_ops = NULL;
782  /* Evicting the operations should schedule this operation */
784  return GNUNET_YES;
785  }
786  for (i = 0; i < op->nqueues; i++)
787  op->queues[i]->active += op->nres[i];
789  rq_add (op);
790  return GNUNET_YES;
791 }
unsigned int * nres
Array of number of resources an operation need from each queue.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void GNUNET_TESTBED_operation_release_(struct GNUNET_TESTBED_Operation *op)
An operation is &#39;done&#39; (was cancelled or finished); remove it from the queues and release associated ...
struct QueueEntry ** qentries
Array of operation queue entries corresponding to this operation in operation queues for this operati...
static void change_state(struct GNUNET_TESTBED_Operation *op, enum OperationState state)
Changes the state of the operation while moving its associated queue entries in the operation&#39;s opera...
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
unsigned int nqueues
Number of queues in the operation queues array.
Opaque handle to an abstract operation to be executed by the testing framework.
The operation is currently waiting for resources.
static int decide_capacity(struct OperationQueue *opq, struct QueueEntry *entry, struct GNUNET_TESTBED_Operation ***ops_, unsigned int *n_ops_)
Checks if the given operation queue has enough resources to provide for the operation of the given qu...
The operation is ready to be started.
struct ReadyQueueEntry * rq_entry
Entry corresponding to this operation in ready queue.
unsigned int active
Number of operations that are currently active in this queue.
enum OperationState state
The state of the operation.
static void rq_add(struct GNUNET_TESTBED_Operation *op)
Adds the operation to the ready queue and starts the &#39;process_rq_task&#39;.
struct OperationQueue ** queues
Array of operation queues this Operation belongs to.
#define GNUNET_YES
Definition: gnunet_common.h:80
static void merge_ops(struct GNUNET_TESTBED_Operation ***old, unsigned int *n_old, struct GNUNET_TESTBED_Operation **new, unsigned int n_new)
Merges an array of operations into another, eliminating duplicates.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ defer()

static void defer ( struct GNUNET_TESTBED_Operation op)
static

Defers a ready to be executed operation back to waiting.

Parameters
opthe operation to defer

Definition at line 800 of file testbed_api_operations.c.

References OperationQueue::active, change_state(), GNUNET_assert, GNUNET_TESTBED_Operation::nqueues, GNUNET_TESTBED_Operation::nres, OP_STATE_READY, OP_STATE_WAITING, GNUNET_TESTBED_Operation::queues, rq_remove(), and GNUNET_TESTBED_Operation::state.

Referenced by GNUNET_TESTBED_operation_queue_reset_max_active_().

801 {
802  unsigned int i;
803 
805  rq_remove (op);
806  for (i = 0; i < op->nqueues; i++)
807  {
808  GNUNET_assert (op->queues[i]->active >= op->nres[i]);
809  op->queues[i]->active -= op->nres[i];
810  }
812 }
unsigned int * nres
Array of number of resources an operation need from each queue.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static void change_state(struct GNUNET_TESTBED_Operation *op, enum OperationState state)
Changes the state of the operation while moving its associated queue entries in the operation&#39;s opera...
unsigned int nqueues
Number of queues in the operation queues array.
The operation is currently waiting for resources.
static void rq_remove(struct GNUNET_TESTBED_Operation *op)
Removes an operation from the ready queue.
The operation is ready to be started.
unsigned int active
Number of operations that are currently active in this queue.
enum OperationState state
The state of the operation.
struct OperationQueue ** queues
Array of operation queues this Operation belongs to.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cleanup_tslots()

static void cleanup_tslots ( struct OperationQueue queue)
static

Cleanups the array of timeslots of an operation queue.

For each time slot in the array, if it is allocated to an operation, it will be deallocated from the operation

Parameters
queuethe operation queue

Definition at line 823 of file testbed_api_operations.c.

References FeedbackCtx::alloc_head, FeedbackCtx::alloc_tail, OperationQueue::fctx, GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_free_non_null, OperationQueue::max_active, QueueEntry::op, TimeSlot::op, FeedbackCtx::tslots_filled, FeedbackCtx::tslots_freeptr, GNUNET_TESTBED_Operation::tslots_head, and GNUNET_TESTBED_Operation::tslots_tail.

Referenced by adaptive_queue_set_max_active(), and queue_destroy().

824 {
825  struct FeedbackCtx *fctx = queue->fctx;
826  struct TimeSlot *tslot;
828  unsigned int cnt;
829 
830  GNUNET_assert (NULL != fctx);
831  for (cnt = 0; cnt < queue->max_active; cnt++)
832  {
833  tslot = &fctx->tslots_freeptr[cnt];
834  op = tslot->op;
835  if (NULL == op)
836  continue;
838  }
840  fctx->tslots_freeptr = NULL;
841  fctx->alloc_head = NULL;
842  fctx->alloc_tail = NULL;
843  fctx->tslots_filled = 0;
844 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct TimeSlot * tslots_head
Head pointer for DLL of tslots allocated to this operation.
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
Context for operation queues of type OPERATION_QUEUE_TYPE_ADAPTIVE.
Opaque handle to an abstract operation to be executed by the testing framework.
struct TimeSlot * alloc_head
Head for DLL of time slots which are free to be allocated to operations.
struct TimeSlot * tslots_tail
Tail pointer for DLL of tslots allocated to this operation.
struct TimeSlot * alloc_tail
Tail for DLL of time slots which are free to be allocated to operations.
struct TimeSlot * tslots_freeptr
Pointer to the chunk of time slots.
A slot to record time taken by an operation.
unsigned int max_active
Max number of operations which can be active at any time in this queue.
struct GNUNET_TESTBED_Operation * op
The operation to which this timeslot is currently allocated to.
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:139
unsigned int tslots_filled
Number of time slots filled so far.
struct FeedbackCtx * fctx
Feedback context; only relevant for adaptive operation queues.
Here is the caller graph for this function:

◆ adaptive_queue_set_max_active()

static void adaptive_queue_set_max_active ( struct OperationQueue queue,
unsigned int  n 
)
static

Cleansup the existing timing slots and sets new timing slots in the given queue to accommodate given number of max active operations.

Parameters
queuethe queue
nthe number of maximum active operations. If n is greater than the maximum limit set while creating the queue, then the minimum of these two will be selected as n

Definition at line 857 of file testbed_api_operations.c.

References FeedbackCtx::alloc_head, FeedbackCtx::alloc_tail, cleanup_tslots(), OperationQueue::fctx, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_malloc, GNUNET_MIN, GNUNET_TESTBED_operation_queue_reset_max_active_(), FeedbackCtx::max_active_bound, FeedbackCtx::nfailed, TimeSlot::queue, QueueEntry::queue, and FeedbackCtx::tslots_freeptr.

Referenced by adapt_parallelism(), and GNUNET_TESTBED_operation_queue_create_().

858 {
859  struct FeedbackCtx *fctx = queue->fctx;
860  struct TimeSlot *tslot;
861  unsigned int cnt;
862 
863  cleanup_tslots (queue);
864  n = GNUNET_MIN (n ,fctx->max_active_bound);
865  fctx->tslots_freeptr = GNUNET_malloc (n * sizeof (struct TimeSlot));
866  fctx->nfailed = 0;
867  for (cnt = 0; cnt < n; cnt++)
868  {
869  tslot = &fctx->tslots_freeptr[cnt];
870  tslot->queue = queue;
872  }
874 }
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
unsigned int nfailed
Number of operations that have failed.
static void cleanup_tslots(struct OperationQueue *queue)
Cleanups the array of timeslots of an operation queue.
Context for operation queues of type OPERATION_QUEUE_TYPE_ADAPTIVE.
unsigned int max_active_bound
Bound on the maximum number of operations which can be active.
#define GNUNET_MIN(a, b)
Definition: gnunet_common.h:83
struct TimeSlot * alloc_head
Head for DLL of time slots which are free to be allocated to operations.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
void GNUNET_TESTBED_operation_queue_reset_max_active_(struct OperationQueue *queue, unsigned int max_active)
Function to reset the maximum number of operations in the given queue.
struct TimeSlot * alloc_tail
Tail for DLL of time slots which are free to be allocated to operations.
struct TimeSlot * tslots_freeptr
Pointer to the chunk of time slots.
A slot to record time taken by an operation.
struct OperationQueue * queue
This operation queue to which this time slot belongs to.
struct FeedbackCtx * fctx
Feedback context; only relevant for adaptive operation queues.
#define GNUNET_malloc(size)
Wrapper around malloc.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ adapt_parallelism()

static void adapt_parallelism ( struct OperationQueue queue)
static

Adapts parallelism in an adaptive queue by using the statistical data from the feedback context.

Parameters
queuethe queue

Definition at line 884 of file testbed_api_operations.c.

References ADAPTIVE_QUEUE_DEFAULT_MAX_ACTIVE, adaptive_queue_set_max_active(), OperationQueue::fctx, GNUNET_assert, GNUNET_MAX, GNUNET_SYSERR, GNUNET_TESTBED_SD_add_data_(), GNUNET_TESTBED_SD_deviation_factor_(), GNUNET_TIME_relative_add(), GNUNET_TIME_relative_divide(), GNUNET_TIME_UNIT_ZERO, OperationQueue::max_active, FeedbackCtx::nfailed, TimeSlot::nvals, parallelism, GNUNET_TIME_Relative::rel_value_us, FeedbackCtx::sd, FeedbackCtx::tslots_freeptr, and TimeSlot::tsum.

Referenced by update_tslots().

885 {
886  struct GNUNET_TIME_Relative avg;
887  struct FeedbackCtx *fctx;
888  struct TimeSlot *tslot;
889  int sd;
890  unsigned int nvals;
891  unsigned int cnt;
892  unsigned int parallelism;
893 
894  avg = GNUNET_TIME_UNIT_ZERO;
895  nvals = 0;
896  fctx = queue->fctx;
897  for (cnt = 0; cnt < queue->max_active; cnt++)
898  {
899  tslot = &fctx->tslots_freeptr[cnt];
900  avg = GNUNET_TIME_relative_add (avg, tslot->tsum);
901  nvals += tslot->nvals;
902  }
903  GNUNET_assert (nvals >= queue->max_active);
904  GNUNET_assert (fctx->nfailed <= nvals);
905  nvals -= fctx->nfailed;
906  if (0 == nvals)
907  {
908  if (1 == queue->max_active)
910  else
911  adaptive_queue_set_max_active (queue, queue->max_active / 2);
912  return;
913  }
914  avg = GNUNET_TIME_relative_divide (avg, nvals);
915  GNUNET_TESTBED_SD_add_data_ (fctx->sd, (unsigned int) avg.rel_value_us);
916  if (GNUNET_SYSERR ==
918  (unsigned int) avg.rel_value_us,
919  &sd))
920  {
921  adaptive_queue_set_max_active (queue, queue->max_active); /* no change */
922  return;
923  }
924 
925  parallelism = 0;
926  if (-1 == sd)
927  parallelism = queue->max_active + 1;
928  if (sd <= -2)
929  parallelism = queue->max_active * 2;
930  if (1 == sd)
931  parallelism = queue->max_active - 1;
932  if (2 <= sd)
933  parallelism = queue->max_active / 2;
934  parallelism = GNUNET_MAX (parallelism, ADAPTIVE_QUEUE_DEFAULT_MAX_ACTIVE);
935  adaptive_queue_set_max_active (queue, parallelism);
936 
937 #if 0
938  /* old algorithm */
939  if (sd < 0)
940  sd = 0;
941  GNUNET_assert (0 <= sd);
942  //GNUNET_TESTBED_SD_add_data_ (fctx->sd, (unsigned int) avg.rel_value_us);
943  if (0 == sd)
944  {
945  adaptive_queue_set_max_active (queue, queue->max_active * 2);
946  return;
947  }
948  if (1 == sd)
949  {
950  adaptive_queue_set_max_active (queue, queue->max_active + 1);
951  return;
952  }
953  if (1 == queue->max_active)
954  {
956  return;
957  }
958  if (2 == sd)
959  {
960  adaptive_queue_set_max_active (queue, queue->max_active - 1);
961  return;
962  }
963  adaptive_queue_set_max_active (queue, queue->max_active / 2);
964 #endif
965 }
static unsigned int parallelism
unsigned int nfailed
Number of operations that have failed.
struct GNUNET_TIME_Relative tsum
Accumulated time.
int GNUNET_TESTBED_SD_deviation_factor_(struct SDHandle *h, unsigned int amount, int *factor)
Calculates the factor by which the given amount differs.
static void adaptive_queue_set_max_active(struct OperationQueue *queue, unsigned int n)
Cleansup the existing timing slots and sets new timing slots in the given queue to accommodate given ...
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Context for operation queues of type OPERATION_QUEUE_TYPE_ADAPTIVE.
#define GNUNET_MAX(a, b)
Definition: gnunet_common.h:85
struct SDHandle * sd
Handle for calculating standard deviation.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
#define ADAPTIVE_QUEUE_DEFAULT_MAX_ACTIVE
The number of parallel opeartions we start with by default for adaptive queues.
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_add(struct GNUNET_TIME_Relative a1, struct GNUNET_TIME_Relative a2)
Add relative times together.
Definition: time.c:576
struct TimeSlot * tslots_freeptr
Pointer to the chunk of time slots.
void GNUNET_TESTBED_SD_add_data_(struct SDHandle *h, unsigned int amount)
Add a reading to SD.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_divide(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Divide relative time by a given factor.
Definition: time.c:525
A slot to record time taken by an operation.
unsigned int max_active
Max number of operations which can be active at any time in this queue.
struct FeedbackCtx * fctx
Feedback context; only relevant for adaptive operation queues.
unsigned int nvals
Number of timing values accumulated.
Time for relative time used by GNUnet, in microseconds.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_tslots()

static void update_tslots ( struct GNUNET_TESTBED_Operation op)
static

update tslots with the operation's completion time.

Additionally, if updating a timeslot makes all timeslots filled in an adaptive operation queue, call adapt_parallelism() for that queue.

Parameters
opthe operation

Definition at line 976 of file testbed_api_operations.c.

References adapt_parallelism(), FeedbackCtx::alloc_head, FeedbackCtx::alloc_tail, GNUNET_TESTBED_Operation::failed, OperationQueue::fctx, GNUNET_assert, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_CONTAINER_DLL_remove, GNUNET_TIME_absolute_get_duration(), GNUNET_TIME_relative_add(), OperationQueue::max_active, FeedbackCtx::nfailed, GNUNET_TESTBED_Operation::nqueues, GNUNET_TESTBED_Operation::nres, TimeSlot::nvals, TimeSlot::op, OperationQueue::overload, TimeSlot::queue, QueueEntry::queue, GNUNET_TESTBED_Operation::queues, FeedbackCtx::tslots_filled, GNUNET_TESTBED_Operation::tslots_head, GNUNET_TESTBED_Operation::tslots_tail, GNUNET_TESTBED_Operation::tstart, and TimeSlot::tsum.

Referenced by GNUNET_TESTBED_operation_release_().

977 {
978  struct OperationQueue *queue;
979  struct GNUNET_TIME_Relative t;
980  struct TimeSlot *tslot;
981  struct FeedbackCtx *fctx;
982  unsigned int i;
983 
985  while (NULL != (tslot = op->tslots_head)) /* update time slots */
986  {
987  queue = tslot->queue;
988  fctx = queue->fctx;
990  tslot->op = NULL;
992  tslot);
993  if (op->failed)
994  {
995  fctx->nfailed++;
996  for (i = 0; i < op->nqueues; i++)
997  if (queue == op->queues[i])
998  break;
999  GNUNET_assert (i != op->nqueues);
1000  op->queues[i]->overload += op->nres[i];
1001  }
1002  tslot->tsum = GNUNET_TIME_relative_add (tslot->tsum, t);
1003  if (0 != tslot->nvals++)
1004  continue;
1005  fctx->tslots_filled++;
1006  if (queue->max_active == fctx->tslots_filled)
1007  adapt_parallelism (queue);
1008  }
1009 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
unsigned int nfailed
Number of operations that have failed.
struct GNUNET_TIME_Relative tsum
Accumulated time.
unsigned int * nres
Array of number of resources an operation need from each queue.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct TimeSlot * tslots_head
Head pointer for DLL of tslots allocated to this operation.
static struct GNUNET_SCHEDULER_Task * t
Main task.
unsigned int nqueues
Number of queues in the operation queues array.
Context for operation queues of type OPERATION_QUEUE_TYPE_ADAPTIVE.
struct GNUNET_TIME_Absolute tstart
The time at which the operation is started.
struct TimeSlot * alloc_head
Head for DLL of time slots which are free to be allocated to operations.
unsigned int overload
The number of resources occupied by failed operations in the current shot.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
struct TimeSlot * tslots_tail
Tail pointer for DLL of tslots allocated to this operation.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_add(struct GNUNET_TIME_Relative a1, struct GNUNET_TIME_Relative a2)
Add relative times together.
Definition: time.c:576
Queue of operations where we can only support a certain number of concurrent operations of a particul...
struct TimeSlot * alloc_tail
Tail for DLL of time slots which are free to be allocated to operations.
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_duration(struct GNUNET_TIME_Absolute whence)
Get the duration of an operation as the difference of the current time and the given start time "henc...
Definition: time.c:373
struct OperationQueue ** queues
Array of operation queues this Operation belongs to.
int failed
Is this a failed operation?
static void adapt_parallelism(struct OperationQueue *queue)
Adapts parallelism in an adaptive queue by using the statistical data from the feedback context...
A slot to record time taken by an operation.
unsigned int max_active
Max number of operations which can be active at any time in this queue.
struct GNUNET_TESTBED_Operation * op
The operation to which this timeslot is currently allocated to.
unsigned int tslots_filled
Number of time slots filled so far.
struct OperationQueue * queue
This operation queue to which this time slot belongs to.
struct FeedbackCtx * fctx
Feedback context; only relevant for adaptive operation queues.
unsigned int nvals
Number of timing values accumulated.
Time for relative time used by GNUnet, in microseconds.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTBED_operation_create_()

struct GNUNET_TESTBED_Operation* GNUNET_TESTBED_operation_create_ ( void *  cls,
OperationStart  start,
OperationRelease  release 
)

Create an 'operation' to be performed.

Parameters
clsclosure for the callbacks
startfunction to call to start the operation
releasefunction to call to close down the operation
Returns
handle to the operation

Definition at line 1021 of file testbed_api_operations.c.

References GNUNET_TESTBED_Operation::cb_cls, GNUNET_new, QueueEntry::op, OP_STATE_INIT, GNUNET_TESTBED_Operation::release, start, GNUNET_TESTBED_Operation::start, and GNUNET_TESTBED_Operation::state.

Referenced by GNUNET_TESTBED_controller_link(), GNUNET_TESTBED_get_slave_config_(), GNUNET_TESTBED_get_statistics(), GNUNET_TESTBED_overlay_configure_topology_va(), GNUNET_TESTBED_overlay_connect(), GNUNET_TESTBED_peer_create(), GNUNET_TESTBED_peer_destroy(), GNUNET_TESTBED_peer_get_information(), GNUNET_TESTBED_peer_manage_service(), GNUNET_TESTBED_peer_start(), GNUNET_TESTBED_peer_stop(), GNUNET_TESTBED_peer_update_configuration(), GNUNET_TESTBED_service_connect(), GNUNET_TESTBED_shutdown_peers(), GST_connection_pool_get_handle(), and GST_neighbour_get_connection().

1023 {
1024  struct GNUNET_TESTBED_Operation *op;
1025 
1026  op = GNUNET_new (struct GNUNET_TESTBED_Operation);
1027  op->start = start;
1028  op->state = OP_STATE_INIT;
1029  op->release = release;
1030  op->cb_cls = cls;
1031  return op;
1032 }
void * cb_cls
Closure for callbacks.
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:39
OperationRelease release
Function to call to clean up after the operation (which may or may not have been started yet)...
The operation is just created and is in initial state.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Opaque handle to an abstract operation to be executed by the testing framework.
enum OperationState state
The state of the operation.
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:139
OperationStart start
Function to call when we have the resources to begin the operation.
Here is the caller graph for this function:

◆ GNUNET_TESTBED_operation_queue_create_()

struct OperationQueue* GNUNET_TESTBED_operation_queue_create_ ( enum OperationQueueType  type,
unsigned int  max_active 
)

Create an operation queue.

Parameters
typethe type of operation queue
max_activemaximum number of operations in this queue that can be active in parallel at the same time
Returns
handle to the queue

Definition at line 1044 of file testbed_api_operations.c.

References ADAPTIVE_QUEUE_DEFAULT_HISTORY, ADAPTIVE_QUEUE_DEFAULT_MAX_ACTIVE, adaptive_queue_set_max_active(), OperationQueue::fctx, GNUNET_new, GNUNET_TESTBED_SD_init_(), OperationQueue::max_active, FeedbackCtx::max_active_bound, OPERATION_QUEUE_TYPE_FIXED, QueueEntry::queue, FeedbackCtx::sd, type, and OperationQueue::type.

Referenced by GNUNET_TESTBED_controller_connect(), GNUNET_TESTBED_get_statistics(), GNUNET_TESTBED_host_create_with_id(), and testbed_run().

1046 {
1047  struct OperationQueue *queue;
1048  struct FeedbackCtx *fctx;
1049 
1050  queue = GNUNET_new (struct OperationQueue);
1051  queue->type = type;
1053  {
1054  queue->max_active = max_active;
1055  }
1056  else
1057  {
1058  fctx = GNUNET_new (struct FeedbackCtx);
1059  fctx->max_active_bound = max_active;
1061  queue->fctx = fctx;
1063  }
1064  return queue;
1065 }
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
static void adaptive_queue_set_max_active(struct OperationQueue *queue, unsigned int n)
Cleansup the existing timing slots and sets new timing slots in the given queue to accommodate given ...
Operation queue which permits a fixed maximum number of operations to be active at any time...
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Context for operation queues of type OPERATION_QUEUE_TYPE_ADAPTIVE.
unsigned int max_active_bound
Bound on the maximum number of operations which can be active.
struct SDHandle * GNUNET_TESTBED_SD_init_(unsigned int max_cnt)
Initialize standard deviation calculation handle.
struct SDHandle * sd
Handle for calculating standard deviation.
enum OperationQueueType type
The type of this opeartion queue.
#define ADAPTIVE_QUEUE_DEFAULT_MAX_ACTIVE
The number of parallel opeartions we start with by default for adaptive queues.
Queue of operations where we can only support a certain number of concurrent operations of a particul...
#define ADAPTIVE_QUEUE_DEFAULT_HISTORY
The number of readings containing past operation&#39;s timing information that we keep track of for adapt...
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
unsigned int max_active
Max number of operations which can be active at any time in this queue.
struct FeedbackCtx * fctx
Feedback context; only relevant for adaptive operation queues.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ queue_destroy()

static void queue_destroy ( struct OperationQueue queue)
static

Cleanup the given operation queue.

Parameters
queuethe operation queue to destroy

Definition at line 1074 of file testbed_api_operations.c.

References cleanup_tslots(), OperationQueue::fctx, GNUNET_free, GNUNET_TESTBED_SD_destroy_(), OPERATION_QUEUE_TYPE_ADAPTIVE, FeedbackCtx::sd, and OperationQueue::type.

Referenced by __attribute__(), and GNUNET_TESTBED_operation_queue_destroy_().

1075 {
1076  struct FeedbackCtx *fctx;
1077 
1078  if (OPERATION_QUEUE_TYPE_ADAPTIVE == queue->type)
1079  {
1080  cleanup_tslots (queue);
1081  fctx = queue->fctx;
1083  GNUNET_free (fctx);
1084  }
1085  GNUNET_free (queue);
1086 }
static void cleanup_tslots(struct OperationQueue *queue)
Cleanups the array of timeslots of an operation queue.
Context for operation queues of type OPERATION_QUEUE_TYPE_ADAPTIVE.
struct SDHandle * sd
Handle for calculating standard deviation.
enum OperationQueueType type
The type of this opeartion queue.
void GNUNET_TESTBED_SD_destroy_(struct SDHandle *h)
Frees the memory allocated to the SD handle.
struct FeedbackCtx * fctx
Feedback context; only relevant for adaptive operation queues.
Operation queue which adapts the number of operations to be active based on the operation completion ...
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTBED_operation_queue_destroy_()

void GNUNET_TESTBED_operation_queue_destroy_ ( struct OperationQueue queue)

Destroys an operation queue.

Destroy an operation queue.

If the queue is still in use by operations it is marked as expired and its resources are released in the destructor GNUNET_TESTBED_operations_fini().

Parameters
queuequeue to destroy

Definition at line 1097 of file testbed_api_operations.c.

References OperationQueue::expired, GNUNET_array_append, GNUNET_assert, GNUNET_YES, is_queue_empty(), n_expired_opqs, and queue_destroy().

Referenced by GNUNET_TESTBED_controller_disconnect(), GNUNET_TESTBED_host_destroy(), GNUNET_TESTBED_operation_queue_destroy_empty_(), and shutdown_task().

1098 {
1099  if (GNUNET_YES != is_queue_empty (queue))
1100  {
1101  GNUNET_assert (0 == queue->expired); /* Are you calling twice on same queue? */
1102  queue->expired = 1;
1104  return;
1105  }
1106  queue_destroy (queue);
1107 }
static int is_queue_empty(struct OperationQueue *opq)
Checks if the given operation queue is empty or not.
static struct OperationQueue ** expired_opqs
Array of operation queues which are to be destroyed.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static void queue_destroy(struct OperationQueue *queue)
Cleanup the given operation queue.
#define GNUNET_array_append(arr, size, element)
Append an element to a list (growing the list by one).
static unsigned int n_expired_opqs
Number of expired operation queues in the above array.
#define GNUNET_YES
Definition: gnunet_common.h:80
unsigned int expired
Is this queue marked for expiry?
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTBED_operation_queue_destroy_empty_()

int GNUNET_TESTBED_operation_queue_destroy_empty_ ( struct OperationQueue queue)

Destroys the operation queue if it is empty.

If not empty return GNUNET_NO.

Parameters
queuethe queue to destroy if empty
Returns
GNUNET_YES if the queue is destroyed. GNUNET_NO if not (because it is not empty)

Definition at line 1118 of file testbed_api_operations.c.

References GNUNET_NO, GNUNET_TESTBED_operation_queue_destroy_(), GNUNET_YES, and is_queue_empty().

Referenced by oprelease_get_stats().

1119 {
1120  if (GNUNET_NO == is_queue_empty (queue))
1121  return GNUNET_NO;
1123  return GNUNET_YES;
1124 }
static int is_queue_empty(struct OperationQueue *opq)
Checks if the given operation queue is empty or not.
#define GNUNET_NO
Definition: gnunet_common.h:81
void GNUNET_TESTBED_operation_queue_destroy_(struct OperationQueue *queue)
Destroys an operation queue.
#define GNUNET_YES
Definition: gnunet_common.h:80
Here is the call graph for this function:
Here is the caller graph for this function:

◆ recheck_waiting()

static void recheck_waiting ( struct OperationQueue opq)
static

Rechecks if any of the operations in the given operation queue's waiting list can be made active.

Parameters
opqthe operation queue

Definition at line 1134 of file testbed_api_operations.c.

References check_readiness(), GNUNET_NO, QueueEntry::next, QueueEntry::op, and OperationQueue::wq_head.

Referenced by GNUNET_TESTBED_operation_inactivate_(), GNUNET_TESTBED_operation_queue_reset_max_active_(), and GNUNET_TESTBED_operation_release_().

1135 {
1136  struct QueueEntry *entry;
1137  struct QueueEntry *entry2;
1138 
1139  entry = opq->wq_head;
1140  while (NULL != entry)
1141  {
1142  entry2 = entry->next;
1143  if (GNUNET_NO == check_readiness (entry->op))
1144  break;
1145  entry = entry2;
1146  }
1147 }
#define GNUNET_NO
Definition: gnunet_common.h:81
static int check_readiness(struct GNUNET_TESTBED_Operation *op)
Checks for the readiness of an operation and schedules a operation start task.
struct QueueEntry * next
The next DLL pointer.
An entry in the operation queue.
struct QueueEntry * wq_head
DLL head for the wait queue.
struct GNUNET_TESTBED_Operation * op
The operation this entry holds.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTBED_operation_queue_reset_max_active_()

void GNUNET_TESTBED_operation_queue_reset_max_active_ ( struct OperationQueue queue,
unsigned int  max_active 
)

Function to reset the maximum number of operations in the given queue.

If max_active is lesser than the number of currently active operations, the active operations are not stopped immediately.

Parameters
queuethe operation queue which has to be modified
max_activethe new maximum number of active operations

Definition at line 1159 of file testbed_api_operations.c.

References OperationQueue::active, defer(), OperationQueue::max_active, QueueEntry::op, OperationQueue::overload, recheck_waiting(), and OperationQueue::rq_head.

Referenced by adaptive_queue_set_max_active().

1161 {
1162  struct QueueEntry *entry;
1163 
1164  queue->max_active = max_active;
1165  queue->overload = 0;
1166  while ( (queue->active > queue->max_active)
1167  && (NULL != (entry = queue->rq_head)) )
1168  defer (entry->op);
1169  recheck_waiting (queue);
1170 }
static void defer(struct GNUNET_TESTBED_Operation *op)
Defers a ready to be executed operation back to waiting.
struct QueueEntry * rq_head
DLL head for the ready queue.
static void recheck_waiting(struct OperationQueue *opq)
Rechecks if any of the operations in the given operation queue&#39;s waiting list can be made active...
unsigned int overload
The number of resources occupied by failed operations in the current shot.
An entry in the operation queue.
unsigned int active
Number of operations that are currently active in this queue.
unsigned int max_active
Max number of operations which can be active at any time in this queue.
struct GNUNET_TESTBED_Operation * op
The operation this entry holds.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTBED_operation_queue_insert2_()

void GNUNET_TESTBED_operation_queue_insert2_ ( struct OperationQueue queue,
struct GNUNET_TESTBED_Operation op,
unsigned int  nres 
)

Add an operation to a queue.

An operation can be in multiple queues at once. Once the operation is inserted into all the queues GNUNET_TESTBED_operation_begin_wait_() has to be called to actually start waiting for the operation to become active.

Parameters
queuequeue to add the operation to
opoperation to add to the queue
nresthe number of units of the resources of queue needed by the operation. Should be greater than 0.

Definition at line 1185 of file testbed_api_operations.c.

References GNUNET_array_append, GNUNET_assert, GNUNET_TESTBED_Operation::nqueues, GNUNET_TESTBED_Operation::nres, and GNUNET_TESTBED_Operation::queues.

Referenced by GNUNET_TESTBED_operation_queue_insert_().

1188 {
1189  unsigned int qsize;
1190 
1191  GNUNET_assert (0 < nres);
1192  qsize = op->nqueues;
1193  GNUNET_array_append (op->queues, op->nqueues, queue);
1194  GNUNET_array_append (op->nres, qsize, nres);
1195  GNUNET_assert (qsize == op->nqueues);
1196 }
unsigned int * nres
Array of number of resources an operation need from each queue.
unsigned int nres
How many units of resources does the operation need.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
unsigned int nqueues
Number of queues in the operation queues array.
#define GNUNET_array_append(arr, size, element)
Append an element to a list (growing the list by one).
struct OperationQueue ** queues
Array of operation queues this Operation belongs to.
Here is the caller graph for this function:

◆ GNUNET_TESTBED_operation_queue_insert_()

void GNUNET_TESTBED_operation_queue_insert_ ( struct OperationQueue queue,
struct GNUNET_TESTBED_Operation op 
)

Add an operation to a queue.

An operation can be in multiple queues at once. Once the operation is inserted into all the queues GNUNET_TESTBED_operation_begin_wait_() has to be called to actually start waiting for the operation to become active. The operation is assumed to take 1 queue resource. Use GNUNET_TESTBED_operation_queue_insert2_() if it requires more than 1

Parameters
queuequeue to add the operation to
opoperation to add to the queue

Definition at line 1211 of file testbed_api_operations.c.

References GNUNET_TESTBED_operation_queue_insert2_().

Referenced by GNUNET_TESTBED_controller_link(), GNUNET_TESTBED_get_slave_config_(), GNUNET_TESTBED_get_statistics(), GNUNET_TESTBED_host_queue_oc_(), GNUNET_TESTBED_overlay_configure_topology_va(), GNUNET_TESTBED_peer_create(), GNUNET_TESTBED_peer_destroy(), GNUNET_TESTBED_peer_get_information(), GNUNET_TESTBED_peer_manage_service(), GNUNET_TESTBED_peer_start(), GNUNET_TESTBED_peer_stop(), GNUNET_TESTBED_peer_update_configuration(), GNUNET_TESTBED_service_connect(), GNUNET_TESTBED_shutdown_peers(), GST_connection_pool_get_handle(), and GST_neighbour_get_connection().

1213 {
1214  return GNUNET_TESTBED_operation_queue_insert2_ (queue, op, 1);
1215 }
void GNUNET_TESTBED_operation_queue_insert2_(struct OperationQueue *queue, struct GNUNET_TESTBED_Operation *op, unsigned int nres)
Add an operation to a queue.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTBED_operation_begin_wait_()

void GNUNET_TESTBED_operation_begin_wait_ ( struct GNUNET_TESTBED_Operation op)

Marks the given operation as waiting on the queues.

Once all queues permit the operation to become active, the operation will be activated. The actual activation will occur in a separate task (thus allowing multiple queue insertions to be made without having the first one instantly trigger the operation if the first queue has sufficient resources).

Parameters
opthe operation to marks as waiting

Definition at line 1228 of file testbed_api_operations.c.

References change_state(), check_readiness(), GNUNET_assert, OP_STATE_WAITING, and GNUNET_TESTBED_Operation::rq_entry.

Referenced by GNUNET_TESTBED_controller_link(), GNUNET_TESTBED_get_slave_config_(), GNUNET_TESTBED_get_statistics(), GNUNET_TESTBED_overlay_configure_topology_va(), GNUNET_TESTBED_overlay_connect(), GNUNET_TESTBED_peer_create(), GNUNET_TESTBED_peer_destroy(), GNUNET_TESTBED_peer_get_information(), GNUNET_TESTBED_peer_manage_service(), GNUNET_TESTBED_peer_start(), GNUNET_TESTBED_peer_stop(), GNUNET_TESTBED_peer_update_configuration(), GNUNET_TESTBED_service_connect(), GNUNET_TESTBED_shutdown_peers(), GST_connection_pool_get_handle(), and GST_neighbour_get_connection().

1229 {
1230  GNUNET_assert (NULL == op->rq_entry);
1232  (void) check_readiness (op);
1233 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static void change_state(struct GNUNET_TESTBED_Operation *op, enum OperationState state)
Changes the state of the operation while moving its associated queue entries in the operation&#39;s opera...
static int check_readiness(struct GNUNET_TESTBED_Operation *op)
Checks for the readiness of an operation and schedules a operation start task.
The operation is currently waiting for resources.
struct ReadyQueueEntry * rq_entry
Entry corresponding to this operation in ready queue.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTBED_operation_inactivate_()

void GNUNET_TESTBED_operation_inactivate_ ( struct GNUNET_TESTBED_Operation op)

Marks an active operation as inactive - the operation will be kept in a ready-to-be-released state and continues to hold resources until another operation contents for them.

Parameters
opthe operation to be marked as inactive. The operation start callback should have been called before for this operation to mark it as inactive.

Definition at line 1246 of file testbed_api_operations.c.

References change_state(), GNUNET_assert, GNUNET_free, GNUNET_malloc, GNUNET_memcpy, GNUNET_TESTBED_Operation::nqueues, OP_STATE_ACTIVE, OP_STATE_INACTIVE, GNUNET_TESTBED_Operation::queues, recheck_waiting(), and GNUNET_TESTBED_Operation::state.

Referenced by GST_neighbour_get_connection_cancel(), and GST_neighbour_release_connection().

1247 {
1248  struct OperationQueue **queues;
1249  size_t ms;
1250  unsigned int nqueues;
1251  unsigned int i;
1252 
1255  nqueues = op->nqueues;
1256  ms = sizeof (struct OperationQueue *) * nqueues;
1257  queues = GNUNET_malloc (ms);
1258  /* Cloning is needed as the operation be released by waiting operations and
1259  hence its nqueues memory ptr will be freed */
1260  GNUNET_memcpy (queues, op->queues, ms);
1261  for (i = 0; i < nqueues; i++)
1262  recheck_waiting (queues[i]);
1263  GNUNET_free (queues);
1264 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
The operation is inactive.
static void change_state(struct GNUNET_TESTBED_Operation *op, enum OperationState state)
Changes the state of the operation while moving its associated queue entries in the operation&#39;s opera...
unsigned int nqueues
Number of queues in the operation queues array.
#define GNUNET_memcpy(dst, src, n)
static void recheck_waiting(struct OperationQueue *opq)
Rechecks if any of the operations in the given operation queue&#39;s waiting list can be made active...
enum OperationState state
The state of the operation.
Queue of operations where we can only support a certain number of concurrent operations of a particul...
struct OperationQueue ** queues
Array of operation queues this Operation belongs to.
The operation has started and is active.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTBED_operation_activate_()

void GNUNET_TESTBED_operation_activate_ ( struct GNUNET_TESTBED_Operation op)

Marks and inactive operation as active.

This fuction should be called to ensure that the oprelease callback will not be called until it is either marked as inactive or released.

Parameters
opthe operation to be marked as active

Definition at line 1275 of file testbed_api_operations.c.

References change_state(), GNUNET_assert, OP_STATE_ACTIVE, OP_STATE_INACTIVE, and GNUNET_TESTBED_Operation::state.

Referenced by GNUNET_TESTBED_operation_release_(), and trigger_notifications().

1276 {
1277 
1280 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
The operation is inactive.
static void change_state(struct GNUNET_TESTBED_Operation *op, enum OperationState state)
Changes the state of the operation while moving its associated queue entries in the operation&#39;s opera...
enum OperationState state
The state of the operation.
The operation has started and is active.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTBED_operation_release_()

void GNUNET_TESTBED_operation_release_ ( struct GNUNET_TESTBED_Operation op)

An operation is 'done' (was cancelled or finished); remove it from the queues and release associated resources.

Parameters
opoperation that finished

Definition at line 1290 of file testbed_api_operations.c.

References OperationQueue::active, GNUNET_TESTBED_Operation::cb_cls, GNUNET_assert, GNUNET_free, GNUNET_free_non_null, GNUNET_TESTBED_operation_activate_(), GNUNET_TESTBED_Operation::nqueues, QueueEntry::nres, GNUNET_TESTBED_Operation::nres, OP_STATE_ACTIVE, OP_STATE_INACTIVE, OP_STATE_INIT, OP_STATE_READY, OP_STATE_WAITING, GNUNET_TESTBED_Operation::qentries, GNUNET_TESTBED_Operation::queues, recheck_waiting(), GNUNET_TESTBED_Operation::release, remove_queue_entry(), rq_remove(), GNUNET_TESTBED_Operation::state, and update_tslots().

Referenced by check_readiness(), GNUNET_TESTBED_operation_done(), and GST_neighbour_list_clean().

1291 {
1292  struct QueueEntry *entry;
1293  struct OperationQueue *opq;
1294  unsigned int i;
1295 
1296  if (OP_STATE_INIT == op->state)
1297  {
1298  GNUNET_free (op);
1299  return;
1300  }
1301  if (OP_STATE_READY == op->state)
1302  rq_remove (op);
1303  if (OP_STATE_INACTIVE == op->state) /* Activate the operation if inactive */
1305  if (OP_STATE_ACTIVE == op->state)
1306  update_tslots (op);
1307  GNUNET_assert (NULL != op->queues);
1308  GNUNET_assert (NULL != op->qentries);
1309  for (i = 0; i < op->nqueues; i++)
1310  {
1311  entry = op->qentries[i];
1312  remove_queue_entry (op, i);
1313  opq = op->queues[i];
1314  switch (op->state)
1315  {
1316  case OP_STATE_INIT:
1317  case OP_STATE_INACTIVE:
1318  GNUNET_assert (0);
1319  break;
1320  case OP_STATE_WAITING:
1321  break;
1322  case OP_STATE_ACTIVE:
1323  case OP_STATE_READY:
1324  GNUNET_assert (0 != opq->active);
1325  GNUNET_assert (opq->active >= entry->nres);
1326  opq->active -= entry->nres;
1327  recheck_waiting (opq);
1328  break;
1329  }
1330  GNUNET_free (entry);
1331  }
1333  GNUNET_free (op->queues);
1334  GNUNET_free (op->nres);
1335  if (NULL != op->release)
1336  op->release (op->cb_cls);
1337  GNUNET_free (op);
1338 }
void * cb_cls
Closure for callbacks.
unsigned int * nres
Array of number of resources an operation need from each queue.
unsigned int nres
How many units of resources does the operation need.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
The operation is inactive.
OperationRelease release
Function to call to clean up after the operation (which may or may not have been started yet)...
struct QueueEntry ** qentries
Array of operation queue entries corresponding to this operation in operation queues for this operati...
The operation is just created and is in initial state.
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
static void update_tslots(struct GNUNET_TESTBED_Operation *op)
update tslots with the operation&#39;s completion time.
unsigned int nqueues
Number of queues in the operation queues array.
The operation is currently waiting for resources.
static void recheck_waiting(struct OperationQueue *opq)
Rechecks if any of the operations in the given operation queue&#39;s waiting list can be made active...
static void rq_remove(struct GNUNET_TESTBED_Operation *op)
Removes an operation from the ready queue.
void GNUNET_TESTBED_operation_activate_(struct GNUNET_TESTBED_Operation *op)
Marks and inactive operation as active.
The operation is ready to be started.
static void remove_queue_entry(struct GNUNET_TESTBED_Operation *op, unsigned int index)
Removes a queue entry of an operation from one of the operation queues&#39; lists depending on the state ...
An entry in the operation queue.
unsigned int active
Number of operations that are currently active in this queue.
enum OperationState state
The state of the operation.
Queue of operations where we can only support a certain number of concurrent operations of a particul...
struct OperationQueue ** queues
Array of operation queues this Operation belongs to.
The operation has started and is active.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTBED_operation_mark_failed()

void GNUNET_TESTBED_operation_mark_failed ( struct GNUNET_TESTBED_Operation op)

Marks an operation as failed.

Parameters
opthe operation to be marked as failed

Definition at line 1347 of file testbed_api_operations.c.

References GNUNET_TESTBED_Operation::failed, and GNUNET_YES.

Referenced by handle_op_fail_event().

1348 {
1349  op->failed = GNUNET_YES;
1350 }
int failed
Is this a failed operation?
#define GNUNET_YES
Definition: gnunet_common.h:80
Here is the caller graph for this function:

◆ __attribute__()

void __attribute__ ( (destructor)  )

Cleanup expired operation queues.

While doing so, also check for any operations which are not completed and warn about them.

Definition at line 1357 of file testbed_api_operations.c.

References GNUNET_ERROR_TYPE_WARNING, GNUNET_free_non_null, GNUNET_log, GNUNET_NO, is_queue_empty(), n_expired_opqs, QueueEntry::queue, and queue_destroy().

1359 {
1360  struct OperationQueue *queue;
1361  unsigned int i;
1362  int warn = 0;
1363 
1364  for (i=0; i < n_expired_opqs; i++)
1365  {
1366  queue = expired_opqs[i];
1367  if (GNUNET_NO == is_queue_empty (queue))
1368  warn = 1;
1369  queue_destroy (queue);
1370  }
1372  n_expired_opqs = 0;
1373  if (warn)
1375  "Be disciplined. Some operations were not marked as done.\n");
1376 
1377 }
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
static int is_queue_empty(struct OperationQueue *opq)
Checks if the given operation queue is empty or not.
static struct OperationQueue ** expired_opqs
Array of operation queues which are to be destroyed.
static void queue_destroy(struct OperationQueue *queue)
Cleanup the given operation queue.
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
Queue of operations where we can only support a certain number of concurrent operations of a particul...
#define GNUNET_log(kind,...)
static unsigned int n_expired_opqs
Number of expired operation queues in the above array.
Here is the call graph for this function:

Variable Documentation

◆ rq_head

struct ReadyQueueEntry* rq_head
static

DLL head for the ready queue.

Definition at line 383 of file testbed_api_operations.c.

◆ rq_tail

struct ReadyQueueEntry* rq_tail
static

DLL tail for the ready queue.

Definition at line 388 of file testbed_api_operations.c.

◆ expired_opqs

struct OperationQueue** expired_opqs
static

Array of operation queues which are to be destroyed.

Definition at line 393 of file testbed_api_operations.c.

◆ n_expired_opqs

unsigned int n_expired_opqs
static

Number of expired operation queues in the above array.

Definition at line 398 of file testbed_api_operations.c.

Referenced by __attribute__(), and GNUNET_TESTBED_operation_queue_destroy_().

◆ process_rq_task_id

struct GNUNET_SCHEDULER_Task* process_rq_task_id

The id of the task to process the ready queue.

Definition at line 403 of file testbed_api_operations.c.