GNUnet  0.11.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 413 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().

415 {
416  struct FeedbackCtx *fctx = queue->fctx;
417  struct TimeSlot *tslot;
418 
420  tslot = fctx->alloc_head;
421  GNUNET_assert (NULL != tslot);
422  GNUNET_CONTAINER_DLL_remove (fctx->alloc_head, fctx->alloc_tail, tslot);
424  tslot->op = op;
425 }
#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:144
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 436 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_().

437 {
438  struct OperationQueue *opq;
439  struct QueueEntry *entry;
440 
441  opq = op->queues[index];
442  entry = op->qentries[index];
443  switch (op->state)
444  {
445  case OP_STATE_INIT:
446  GNUNET_assert (0);
447  break;
448 
449  case OP_STATE_WAITING:
450  GNUNET_CONTAINER_DLL_remove (opq->wq_head, opq->wq_tail, entry);
451  break;
452 
453  case OP_STATE_READY:
454  GNUNET_CONTAINER_DLL_remove (opq->rq_head, opq->rq_tail, entry);
455  break;
456 
457  case OP_STATE_ACTIVE:
458  GNUNET_CONTAINER_DLL_remove (opq->aq_head, opq->aq_tail, entry);
459  break;
460 
461  case OP_STATE_INACTIVE:
462  GNUNET_CONTAINER_DLL_remove (opq->nq_head, opq->nq_tail, entry);
463  break;
464  }
465 }
#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 476 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().

477 {
478  struct QueueEntry *entry;
479  struct OperationQueue *opq;
480  unsigned int cnt;
481  unsigned int s;
482 
484  GNUNET_assert (NULL != op->queues);
485  GNUNET_assert (NULL != op->nres);
486  GNUNET_assert ((OP_STATE_INIT == op->state) || (NULL != op->qentries));
487  GNUNET_assert (op->state != state);
488  for (cnt = 0; cnt < op->nqueues; cnt++)
489  {
490  if (OP_STATE_INIT == op->state)
491  {
492  entry = GNUNET_new (struct QueueEntry);
493  entry->op = op;
494  entry->nres = op->nres[cnt];
495  s = cnt;
496  GNUNET_array_append (op->qentries, s, entry);
497  }
498  else
499  {
500  entry = op->qentries[cnt];
501  remove_queue_entry (op, cnt);
502  }
503  opq = op->queues[cnt];
504  switch (state)
505  {
506  case OP_STATE_INIT:
507  GNUNET_assert (0);
508  break;
509 
510  case OP_STATE_WAITING:
512  break;
513 
514  case OP_STATE_READY:
516  break;
517 
518  case OP_STATE_ACTIVE:
520  break;
521 
522  case OP_STATE_INACTIVE:
524  break;
525  }
526  }
527  op->state = state;
528 }
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:144
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 538 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().

539 {
540  GNUNET_assert (NULL != op->rq_entry);
542  GNUNET_free (op->rq_entry);
543  op->rq_entry = NULL;
544  if ((NULL == rq_head) && (NULL != process_rq_task_id))
545  {
547  process_rq_task_id = NULL;
548  }
549 }
#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:966
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 561 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().

562 {
564  struct OperationQueue *queue;
565  unsigned int cnt;
566 
567  process_rq_task_id = NULL;
568  GNUNET_assert (NULL != rq_head);
569  GNUNET_assert (NULL != (op = rq_head->op));
570  rq_remove (op);
571  if (NULL != rq_head)
574  for (cnt = 0; cnt < op->nqueues; cnt++)
575  {
576  queue = op->queues[cnt];
577  if (OPERATION_QUEUE_TYPE_ADAPTIVE == queue->type)
578  assign_timeslot (op, queue);
579  }
581  if (NULL != op->start)
582  op->start (op->cb_cls);
583 }
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:1280
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:144
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 592 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().

593 {
594  struct ReadyQueueEntry *rq_entry;
595 
596  GNUNET_assert (NULL == op->rq_entry);
597  rq_entry = GNUNET_new (struct ReadyQueueEntry);
598  rq_entry->op = op;
600  op->rq_entry = rq_entry;
601  if (NULL == process_rq_task_id)
603 }
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:1280
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:144
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 614 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_().

615 {
616  if ((NULL != opq->wq_head)
617  || (NULL != opq->rq_head)
618  || (NULL != opq->aq_head)
619  || (NULL != opq->nq_head))
620  return GNUNET_NO;
621  return GNUNET_YES;
622 }
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:78
struct QueueEntry * rq_head
DLL head for the ready queue.
#define GNUNET_YES
Definition: gnunet_common.h:77
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 642 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().

646 {
647  struct QueueEntry **evict_entries;
648  struct GNUNET_TESTBED_Operation **ops;
650  unsigned int n_ops;
651  unsigned int n_evict_entries;
652  unsigned int need;
653  unsigned int max;
654  int deficit;
655  int rval;
656 
657  GNUNET_assert (NULL != (op = entry->op));
658  GNUNET_assert (0 < (need = entry->nres));
659  ops = NULL;
660  n_ops = 0;
661  evict_entries = NULL;
662  n_evict_entries = 0;
663  rval = GNUNET_YES;
665  {
666  GNUNET_assert (NULL != opq->fctx);
667  GNUNET_assert (opq->max_active >= opq->overload);
668  max = opq->max_active - opq->overload;
669  }
670  else
671  max = opq->max_active;
672  if (opq->active > max)
673  {
674  rval = GNUNET_NO;
675  goto ret;
676  }
677  if ((opq->active + need) <= max)
678  goto ret;
679  deficit = need - (max - opq->active);
680  for (entry = opq->nq_head;
681  (0 < deficit) && (NULL != entry);
682  entry = entry->next)
683  {
684  GNUNET_array_append (evict_entries, n_evict_entries, entry);
685  deficit -= entry->nres;
686  }
687  if (0 < deficit)
688  {
689  rval = GNUNET_NO;
690  goto ret;
691  }
692  for (n_ops = 0; n_ops < n_evict_entries;)
693  {
694  op = evict_entries[n_ops]->op;
695  GNUNET_array_append (ops, n_ops, op); /* increments n-ops */
696  }
697 
698 ret:
699  GNUNET_free_non_null (evict_entries);
700  if (NULL != ops_)
701  *ops_ = ops;
702  else
703  GNUNET_free (ops);
704  if (NULL != n_ops_)
705  *n_ops_ = n_ops;
706  return rval;
707 }
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.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
struct QueueEntry * nq_head
DLL head for the inactive queue.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
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:77
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:144
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 720 of file testbed_api_operations.c.

References GNUNET_array_append, and GNUNET_assert.

Referenced by check_readiness().

724 {
725  struct GNUNET_TESTBED_Operation **cur;
726  unsigned int i;
727  unsigned int j;
728  unsigned int n_cur;
729 
730  GNUNET_assert (NULL != old);
731  n_cur = *n_old;
732  cur = *old;
733  for (i = 0; i < n_new; i++)
734  {
735  for (j = 0; j < *n_old; j++)
736  {
737  if (new[i] == cur[j])
738  break;
739  }
740  if (j < *n_old)
741  continue;
742  GNUNET_array_append (cur, n_cur, new[j]);
743  }
744  *old = cur;
745  *n_old = n_cur;
746 }
#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 755 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().

756 {
757  struct GNUNET_TESTBED_Operation **evict_ops;
758  struct GNUNET_TESTBED_Operation **ops;
759  unsigned int n_ops;
760  unsigned int n_evict_ops;
761  unsigned int i;
762 
763  GNUNET_assert (NULL == op->rq_entry);
765  evict_ops = NULL;
766  n_evict_ops = 0;
767  for (i = 0; i < op->nqueues; i++)
768  {
769  ops = NULL;
770  n_ops = 0;
771  if (GNUNET_NO == decide_capacity (op->queues[i], op->qentries[i],
772  &ops, &n_ops))
773  {
774  GNUNET_free_non_null (evict_ops);
775  return GNUNET_NO;
776  }
777  if (NULL == ops)
778  continue;
779  merge_ops (&evict_ops, &n_evict_ops, ops, n_ops);
780  GNUNET_free (ops);
781  }
782  if (NULL != evict_ops)
783  {
784  for (i = 0; i < n_evict_ops; i++)
785  GNUNET_TESTBED_operation_release_ (evict_ops[i]);
786  GNUNET_free (evict_ops);
787  evict_ops = NULL;
788  /* Evicting the operations should schedule this operation */
790  return GNUNET_YES;
791  }
792  for (i = 0; i < op->nqueues; i++)
793  op->queues[i]->active += op->nres[i];
795  rq_add (op);
796  return GNUNET_YES;
797 }
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:78
#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:77
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 806 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_().

807 {
808  unsigned int i;
809 
811  rq_remove (op);
812  for (i = 0; i < op->nqueues; i++)
813  {
814  GNUNET_assert (op->queues[i]->active >= op->nres[i]);
815  op->queues[i]->active -= op->nres[i];
816  }
818 }
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 829 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().

830 {
831  struct FeedbackCtx *fctx = queue->fctx;
832  struct TimeSlot *tslot;
834  unsigned int cnt;
835 
836  GNUNET_assert (NULL != fctx);
837  for (cnt = 0; cnt < queue->max_active; cnt++)
838  {
839  tslot = &fctx->tslots_freeptr[cnt];
840  op = tslot->op;
841  if (NULL == op)
842  continue;
844  }
846  fctx->tslots_freeptr = NULL;
847  fctx->alloc_head = NULL;
848  fctx->alloc_tail = NULL;
849  fctx->tslots_filled = 0;
850 }
#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:144
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 863 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_().

864 {
865  struct FeedbackCtx *fctx = queue->fctx;
866  struct TimeSlot *tslot;
867  unsigned int cnt;
868 
869  cleanup_tslots (queue);
870  n = GNUNET_MIN (n, fctx->max_active_bound);
871  fctx->tslots_freeptr = GNUNET_malloc (n * sizeof(struct TimeSlot));
872  fctx->nfailed = 0;
873  for (cnt = 0; cnt < n; cnt++)
874  {
875  tslot = &fctx->tslots_freeptr[cnt];
876  tslot->queue = queue;
878  tslot);
879  }
881 }
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:80
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 891 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().

892 {
893  struct GNUNET_TIME_Relative avg;
894  struct FeedbackCtx *fctx;
895  struct TimeSlot *tslot;
896  int sd;
897  unsigned int nvals;
898  unsigned int cnt;
899  unsigned int parallelism;
900 
901  avg = GNUNET_TIME_UNIT_ZERO;
902  nvals = 0;
903  fctx = queue->fctx;
904  for (cnt = 0; cnt < queue->max_active; cnt++)
905  {
906  tslot = &fctx->tslots_freeptr[cnt];
907  avg = GNUNET_TIME_relative_add (avg, tslot->tsum);
908  nvals += tslot->nvals;
909  }
910  GNUNET_assert (nvals >= queue->max_active);
911  GNUNET_assert (fctx->nfailed <= nvals);
912  nvals -= fctx->nfailed;
913  if (0 == nvals)
914  {
915  if (1 == queue->max_active)
917  else
918  adaptive_queue_set_max_active (queue, queue->max_active / 2);
919  return;
920  }
921  avg = GNUNET_TIME_relative_divide (avg, nvals);
922  GNUNET_TESTBED_SD_add_data_ (fctx->sd, (unsigned int) avg.rel_value_us);
923  if (GNUNET_SYSERR ==
925  (unsigned int) avg.rel_value_us,
926  &sd))
927  {
928  adaptive_queue_set_max_active (queue, queue->max_active); /* no change */
929  return;
930  }
931 
932  parallelism = 0;
933  if (-1 == sd)
934  parallelism = queue->max_active + 1;
935  if (sd <= -2)
936  parallelism = queue->max_active * 2;
937  if (1 == sd)
938  parallelism = queue->max_active - 1;
939  if (2 <= sd)
940  parallelism = queue->max_active / 2;
941  parallelism = GNUNET_MAX (parallelism, ADAPTIVE_QUEUE_DEFAULT_MAX_ACTIVE);
942  adaptive_queue_set_max_active (queue, parallelism);
943 
944 #if 0
945  /* old algorithm */
946  if (sd < 0)
947  sd = 0;
948  GNUNET_assert (0 <= sd);
949  // GNUNET_TESTBED_SD_add_data_ (fctx->sd, (unsigned int) avg.rel_value_us);
950  if (0 == sd)
951  {
952  adaptive_queue_set_max_active (queue, queue->max_active * 2);
953  return;
954  }
955  if (1 == sd)
956  {
957  adaptive_queue_set_max_active (queue, queue->max_active + 1);
958  return;
959  }
960  if (1 == queue->max_active)
961  {
963  return;
964  }
965  if (2 == sd)
966  {
967  adaptive_queue_set_max_active (queue, queue->max_active - 1);
968  return;
969  }
970  adaptive_queue_set_max_active (queue, queue->max_active / 2);
971 #endif
972 }
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:82
struct SDHandle * sd
Handle for calculating standard deviation.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
#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:579
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:527
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 983 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_().

984 {
985  struct OperationQueue *queue;
986  struct GNUNET_TIME_Relative t;
987  struct TimeSlot *tslot;
988  struct FeedbackCtx *fctx;
989  unsigned int i;
990 
992  while (NULL != (tslot = op->tslots_head)) /* update time slots */
993  {
994  queue = tslot->queue;
995  fctx = queue->fctx;
997  tslot->op = NULL;
999  tslot);
1000  if (op->failed)
1001  {
1002  fctx->nfailed++;
1003  for (i = 0; i < op->nqueues; i++)
1004  if (queue == op->queues[i])
1005  break;
1006  GNUNET_assert (i != op->nqueues);
1007  op->queues[i]->overload += op->nres[i];
1008  }
1009  tslot->tsum = GNUNET_TIME_relative_add (tslot->tsum, t);
1010  if (0 != tslot->nvals++)
1011  continue;
1012  fctx->tslots_filled++;
1013  if (queue->max_active == fctx->tslots_filled)
1014  adapt_parallelism (queue);
1015  }
1016 }
#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:579
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:375
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 1028 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().

1030 {
1031  struct GNUNET_TESTBED_Operation *op;
1032 
1033  op = GNUNET_new (struct GNUNET_TESTBED_Operation);
1034  op->start = start;
1035  op->state = OP_STATE_INIT;
1036  op->release = release;
1037  op->cb_cls = cls;
1038  return op;
1039 }
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:144
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 1051 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().

1053 {
1054  struct OperationQueue *queue;
1055  struct FeedbackCtx *fctx;
1056 
1057  queue = GNUNET_new (struct OperationQueue);
1058  queue->type = type;
1060  {
1061  queue->max_active = max_active;
1062  }
1063  else
1064  {
1065  fctx = GNUNET_new (struct FeedbackCtx);
1066  fctx->max_active_bound = max_active;
1068  queue->fctx = fctx;
1070  }
1071  return queue;
1072 }
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 1081 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_().

1082 {
1083  struct FeedbackCtx *fctx;
1084 
1085  if (OPERATION_QUEUE_TYPE_ADAPTIVE == queue->type)
1086  {
1087  cleanup_tslots (queue);
1088  fctx = queue->fctx;
1090  GNUNET_free (fctx);
1091  }
1092  GNUNET_free (queue);
1093 }
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 1104 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().

1105 {
1106  if (GNUNET_YES != is_queue_empty (queue))
1107  {
1108  GNUNET_assert (0 == queue->expired); /* Are you calling twice on same queue? */
1109  queue->expired = 1;
1111  return;
1112  }
1113  queue_destroy (queue);
1114 }
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:77
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 1125 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().

1126 {
1127  if (GNUNET_NO == is_queue_empty (queue))
1128  return GNUNET_NO;
1130  return GNUNET_YES;
1131 }
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:78
void GNUNET_TESTBED_operation_queue_destroy_(struct OperationQueue *queue)
Destroys an operation queue.
#define GNUNET_YES
Definition: gnunet_common.h:77
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 1141 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_().

1142 {
1143  struct QueueEntry *entry;
1144  struct QueueEntry *entry2;
1145 
1146  entry = opq->wq_head;
1147  while (NULL != entry)
1148  {
1149  entry2 = entry->next;
1150  if (GNUNET_NO == check_readiness (entry->op))
1151  break;
1152  entry = entry2;
1153  }
1154 }
#define GNUNET_NO
Definition: gnunet_common.h:78
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 1166 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().

1168 {
1169  struct QueueEntry *entry;
1170 
1171  queue->max_active = max_active;
1172  queue->overload = 0;
1173  while ((queue->active > queue->max_active)
1174  && (NULL != (entry = queue->rq_head)))
1175  defer (entry->op);
1176  recheck_waiting (queue);
1177 }
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 1192 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_().

1195 {
1196  unsigned int qsize;
1197 
1198  GNUNET_assert (0 < nres);
1199  qsize = op->nqueues;
1200  GNUNET_array_append (op->queues, op->nqueues, queue);
1201  GNUNET_array_append (op->nres, qsize, nres);
1202  GNUNET_assert (qsize == op->nqueues);
1203 }
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 1218 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().

1220 {
1221  return GNUNET_TESTBED_operation_queue_insert2_ (queue, op, 1);
1222 }
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 1235 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().

1236 {
1237  GNUNET_assert (NULL == op->rq_entry);
1239  (void) check_readiness (op);
1240 }
#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 1253 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().

1254 {
1255  struct OperationQueue **queues;
1256  size_t ms;
1257  unsigned int nqueues;
1258  unsigned int i;
1259 
1262  nqueues = op->nqueues;
1263  ms = sizeof(struct OperationQueue *) * nqueues;
1264  queues = GNUNET_malloc (ms);
1265  /* Cloning is needed as the operation be released by waiting operations and
1266  hence its nqueues memory ptr will be freed */
1267  GNUNET_memcpy (queues, op->queues, ms);
1268  for (i = 0; i < nqueues; i++)
1269  recheck_waiting (queues[i]);
1270  GNUNET_free (queues);
1271 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
The operation is inactive.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
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.
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 1282 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().

1283 {
1286 }
#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 1296 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().

1297 {
1298  struct QueueEntry *entry;
1299  struct OperationQueue *opq;
1300  unsigned int i;
1301 
1302  if (OP_STATE_INIT == op->state)
1303  {
1304  GNUNET_free (op);
1305  return;
1306  }
1307  if (OP_STATE_READY == op->state)
1308  rq_remove (op);
1309  if (OP_STATE_INACTIVE == op->state) /* Activate the operation if inactive */
1311  if (OP_STATE_ACTIVE == op->state)
1312  update_tslots (op);
1313  GNUNET_assert (NULL != op->queues);
1314  GNUNET_assert (NULL != op->qentries);
1315  for (i = 0; i < op->nqueues; i++)
1316  {
1317  entry = op->qentries[i];
1318  remove_queue_entry (op, i);
1319  opq = op->queues[i];
1320  switch (op->state)
1321  {
1322  case OP_STATE_INIT:
1323  case OP_STATE_INACTIVE:
1324  GNUNET_assert (0);
1325  break;
1326 
1327  case OP_STATE_WAITING:
1328  break;
1329 
1330  case OP_STATE_ACTIVE:
1331  case OP_STATE_READY:
1332  GNUNET_assert (0 != opq->active);
1333  GNUNET_assert (opq->active >= entry->nres);
1334  opq->active -= entry->nres;
1335  recheck_waiting (opq);
1336  break;
1337  }
1338  GNUNET_free (entry);
1339  }
1341  GNUNET_free (op->queues);
1342  GNUNET_free (op->nres);
1343  if (NULL != op->release)
1344  op->release (op->cb_cls);
1345  GNUNET_free (op);
1346 }
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 1355 of file testbed_api_operations.c.

References GNUNET_TESTBED_Operation::failed, and GNUNET_YES.

Referenced by handle_op_fail_event().

1356 {
1357  op->failed = GNUNET_YES;
1358 }
int failed
Is this a failed operation?
#define GNUNET_YES
Definition: gnunet_common.h:77
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 1365 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().

1367 {
1368  struct OperationQueue *queue;
1369  unsigned int i;
1370  int warn = 0;
1371 
1372  for (i = 0; i < n_expired_opqs; i++)
1373  {
1374  queue = expired_opqs[i];
1375  if (GNUNET_NO == is_queue_empty (queue))
1376  warn = 1;
1377  queue_destroy (queue);
1378  }
1380  n_expired_opqs = 0;
1381  if (warn)
1383  "Be disciplined. Some operations were not marked as done.\n");
1384 }
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:78
#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 382 of file testbed_api_operations.c.

◆ rq_tail

struct ReadyQueueEntry* rq_tail
static

DLL tail for the ready queue.

Definition at line 387 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 392 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 397 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 402 of file testbed_api_operations.c.