Exemplo n.º 1
0
int
event_queue_get(struct event_queue *eq, struct queue_thread *me, struct server_msg **msg)
{
  struct event_queue_msg *el;
  int found;

  assert(eq != NULL);

  event_queue_lock(eq);
  if(me->jobid) {
	  me->jobid = NULL;
	  me->current = NULL;
  }
  if(NULL == eq->head) {
	  event_queue_unlock(eq);
	  return 0;
  }
  found = 0;
  el = eq->head;
  do {
	  char *jobid = el->msg->job_id_s;
	  int i;
	  
	  for(i = 0; i < eq->num_threads; i++) {
		  if(me == eq->thread + i) {
			  continue;
		  }
		  if(eq->thread[i].jobid && strcmp(jobid, eq->thread[i].jobid) == 0) {
			  break;
		  }
	  }
	  if(i >= eq->num_threads) {
		  /* no other thread is working on this job */
		  found = 1;
		  break;
	  }
	  el = el->prev;
  } while(el != eq->head);
  if(found && msg) {
	  me->current = el;
	  me->jobid = el->msg->job_id_s;
	  *msg = el->msg;
	  server_msg_use(*msg);
  }
  event_queue_unlock(eq);

  return found;
}
Exemplo n.º 2
0
Arquivo: pmda.c Projeto: Aconex/pcp
static int
etw_fetchCallBack(pmdaMetric *mdesc, unsigned int inst, pmAtomValue *atom)
{
    __pmID_int *idp = (__pmID_int *)&(mdesc->m_desc.pmid);
    etw_event_t	*etw;
    int		sts = PMDA_FETCH_STATIC;

    __pmNotifyErr(LOG_WARNING, "called %s, mdesc=%p", __FUNCTION__, mdesc);

    switch (idp->cluster) {
    case CLUSTER_KERNEL_PROCESS:
	if ((etw = ((mdesc != NULL) ? mdesc->m_user : NULL)) == NULL)
	    return PM_ERR_PMID;

	switch (idp->item) {
	    case 0:		/* etw.kernel.process.start.count */
	    case 20:		/* etw.kernel.process.exit.count */
	    case 50:		/* etw.kernel.thread.start.count */
	    case 70:		/* etw.kernel.thread.stop.count */
	    case 90:		/* etw.kernel.process.image_load.count */
	    case 110:		/* etw.kernel.process.image_unload.count */
		sts = pmdaEventQueueCounter(etw->queueid, atom);
		break;
	    case 1:		/* etw.kernel.process.start.records */
	    case 21:		/* etw.kernel.process.exit.records */
	    case 51:		/* etw.kernel.thread.start.records */
	    case 71:		/* etw.kernel.thread.stop.records */
	    case 91:		/* etw.kernel.process.image_load.records */
	    case 111:		/* etw.kernel.process.image_unload.records */
		event_queue_lock(etw);
		sts = pmdaEventQueueRecords(etw->queueid, atom,
					    pmdaGetContext(),
					    event_decoder, &etw);
		event_queue_unlock(etw);
		break;
	    case 2:		/* etw.kernel.process.start.numclients */
	    case 22:		/* etw.kernel.process.exit.numclients */
	    case 52:		/* etw.kernel.thread.start.numclients */
	    case 72:		/* etw.kernel.thread.stop.numclients */
	    case 92:		/* etw.kernel.process.image_load.numclients */
	    case 112:		/* etw.kernel.process.image_unload.numclients */
		sts = pmdaEventQueueClients(etw->queueid, atom);
		break;
	    case 3:		/* etw.kernel.process.start.queuemem */
	    case 23:		/* etw.kernel.process.exit.queuemem */
	    case 53:		/* etw.kernel.thread.start.queuemem */
	    case 73:		/* etw.kernel.thread.stop.queuemem */
	    case 93:		/* etw.kernel.process.image_load.queuemem */
	    case 113:		/* etw.kernel.process.image_unload.queuemem */
		sts = pmdaEventQueueMemory(etw->queueid, atom);
		break;
	    default:
		return PM_ERR_PMID;
	}
	break;

    case CLUSTER_CONFIGURATION:
	switch (idp->item) {
	    case 0:			/* etw.numclients */
		sts = pmdaEventClients(atom);
		break;
	    default:
		return PM_ERR_PMID;
	}
    	break;

    default:
    	break;
    }

    return sts;
}
Exemplo n.º 3
0
int
event_queue_move_events(struct event_queue *eq_s,
			struct event_queue *eq_d,
			int (*cmp_func)(struct server_msg *, void *),
			void *data)
{
	struct event_queue_msg *p, *q, *last;
	/* struct event_queue_msg **source_prev, **dest_tail; */

	assert(eq_s != NULL);
	assert(data != NULL);

	event_queue_lock(eq_s);

	p = eq_s->head;
	if(NULL == p) {
		event_queue_unlock(eq_s);
		return 0;
	}
	if(eq_d) {
		event_queue_lock(eq_d);
	}

	last = p->next;
	do {
		if((*cmp_func)(p->msg, data)) {
			glite_common_log(IL_LOG_CATEGORY, LOG_PRIORITY_DEBUG, 
					 "      moving event at offset %d(%d) from %s:%d to %s:%d",
					 p->msg->offset, p->msg->generation, eq_s->dest_name, eq_s->dest_port,
					 eq_d ? eq_d->dest_name : "trash", eq_d ? eq_d->dest_port : -1);
			q = p->prev;
			/* remove message from the source queue */
			if(p == p->prev) {
				/* removing last message */
				eq_s->head = NULL;
				eq_s->tail_ems = NULL;
			} else {
				p->next->prev = p->prev;
				p->prev->next = p->next;
				if(p == eq_s->head) {
					eq_s->head = p->prev;
				}
				if(p == eq_s->tail_ems) {
					eq_s->tail_ems = p->prev;
				}
			}
			eq_s->cur_len--;
			if(eq_d) {
				/* append message to the destination queue */
				if(eq_d->head == NULL) {
					eq_d->head = p;
					eq_d->tail_ems = p;
					p->next = p;
					p->prev = p;
				} else {
					/* priorities are ignored */
					p->next = eq_d->head->next;
					p->prev = eq_d->head;
					p->next->prev = p;
					p->prev->next = p;

				}
				if(++eq_d->cur_len > eq_d->max_len) {
					eq_d->max_len = eq_d->cur_len;
				}
				p->eq = eq_d;
			} else {
				/* signal that the message was 'delivered' */
				event_store_commit(p->msg->es, p->msg->ev_len, queue_list_is_log(eq_s),
						   p->msg->generation);
				/* free the message */
				server_msg_free(p->msg);
				free(p);
			}
			p = q;
		} else {
			p = p->prev;
		}
	} while (eq_s->head && p != last);

#if 0 /* OLD IMPLEMENTATION */
	if(eq_d) {
		event_queue_lock(eq_d);
		/* dest tail is set to point to the last (NULL) pointer in the list */
		dest_tail = (eq_d->head == NULL) ? &(eq_d->head) : &(eq_d->tail->prev);
	}
	source_prev = &(eq_s->head);
	p = *source_prev;
	eq_s->tail = NULL;
	while(p) {
		if((*cmp_func)(p->msg, data)) {
			glite_common_log(IL_LOG_CATEGORY, LOG_PRIORITY_DEBUG, 
					 "      moving event at offset %ld(%d) from %s:%d to %s:%d",
					 p->msg->offset, p->msg->generation, eq_s->dest_name, eq_s->dest_port,
			   eq_d ? eq_d->dest_name : "trash", eq_d ? eq_d->dest_port : -1);
			/* il_log(LOG_DEBUG, "  current: %x, next: %x\n", p, p->prev); */
			/* remove the message from the source list */
			*source_prev = p->prev;
			assert(eq_s->cur_len > 0);
			eq_s->cur_len--;
			if(eq_d) {
				/* append the message at the end of destination list */
				p->prev = NULL;
				*dest_tail = p;
				dest_tail = &(p->prev);
				eq_d->tail = p;
				if(++eq_d->cur_len > eq_d->max_len) {
					eq_d->max_len = eq_d->cur_len;
				}
			} else {
				/* signal that the message was 'delivered' */
				event_store_commit(p->msg->es, p->msg->ev_len, queue_list_is_log(eq_s),
						   p->msg->generation);
				/* free the message */
				server_msg_free(p->msg);
				free(p);
			}
		} else {
			/* message stays */
			source_prev = &(p->prev);
			eq_s->tail = p;
		}
		p = *source_prev;
	}
#endif /* OLD IMPLEMENTATION */

	if(eq_s->cur_len <= queue_size_low) {
		eq_s->throttling = 0;
	}
	if(eq_d) event_queue_unlock(eq_d);
	event_queue_unlock(eq_s);
	return(0);
}
Exemplo n.º 4
0
int
event_queue_remove(struct event_queue *eq, struct queue_thread *me)
{
  struct event_queue_msg *el;
#if defined(INTERLOGD_EMS)
  struct event_queue_msg *prev;
#endif

  assert(eq != NULL);
  
  el = me->current;
  if(NULL == el) {
	  return -1;
  }

  /* this is critical section */
  event_queue_lock(eq);

  me->current = NULL;
  me->jobid = NULL;

  if(eq == el->eq) {
	  /* message is still ours, remove from queue */
	  if(el == el->prev) {
		  /* last element */
		  eq->head = NULL;
		  eq->tail_ems = NULL;
	  } else {
		  el->next->prev = el->prev;
		  el->prev->next = el->next;
		  if(el == eq->head) {
			  eq->head = el->prev;
		  }
		  if(el == eq->tail_ems) {
			  eq->tail_ems = el->prev;
		  }
	  }
	  
	  if(--eq->cur_len == 0)
		  eq->times_empty++;
	  
	  if(eq->cur_len <= queue_size_low) {
		  eq->throttling = 0;
	  }
  } else {
	  /* not ours anymore */
	  server_msg_release(el->msg);
	  event_queue_unlock(eq);
	  return 0;
  }

#if 0 /* OLD IMPLEMENTATION */
#if defined(INTERLOGD_EMS)
  el = eq->mark_this;
  prev = eq->mark_prev;

  if(el == NULL) {
    event_queue_unlock(eq);
    return(-1);
  }

  if(prev == NULL) {
    /* removing from head of the queue */
    eq->head = el->prev;
  } else {
    /* removing from middle of the queue */
    prev->prev = el->prev;
  }
  if(el == eq->tail) {
    /* we are removing the last message */
    eq->tail = prev;
  }
  if(el == eq->tail_ems) {
    /* we are removing last priority message */
    eq->tail_ems = prev;
  }

  eq->mark_this = NULL;
  eq->mark_prev = NULL;
#else
  el = eq->head;
  if(el == NULL) {
	  event_queue_unlock(eq);
	  return(-1);
  }
  eq->head = el->prev;
  if(el == eq->tail) {
	  eq->tail = NULL;
  }
#endif
#endif /* OLD IMPLEMENTATION */

  
  event_queue_unlock(eq);
  /* end of critical section */

  server_msg_free(el->msg);
  free(el);

  return(0);
}
Exemplo n.º 5
0
int
event_queue_insert(struct event_queue *eq, struct server_msg *msg)
{
  struct event_queue_msg *el;
#if defined(INTERLOGD_EMS)
  struct event_queue_msg *tail;
#endif

  assert(eq != NULL);

  if(queue_size_high > 0 && (eq->cur_len >= queue_size_high || eq->throttling)) {
	  eq->throttling = 1;
	  return 1;
  }

  if((el = malloc(sizeof(*el))) == NULL)
    return(set_error(IL_NOMEM, ENOMEM, "event_queue_insert: not enough room for queue element"));

  el->msg = server_msg_copy(msg);
  if(el->msg == NULL) {
    free(el);
    return(-1);
  };

  /* this is critical section */
  event_queue_lock(eq);
  if(NULL == eq->head) {
	  el->prev = el;
	  el->next = el;
	  eq->head = el;
	  eq->tail_ems = el;
  } else {
	  if(server_msg_is_priority(msg)) {
		  el->next = eq->tail_ems->next;
		  el->prev = eq->tail_ems;
		  if(eq->head == eq->tail_ems) {
			  eq->head = el;
		  }
	  } else {
		  el->next = eq->head->next;
		  el->prev = eq->head;
	  }
	  el->next->prev = el;
	  el->prev->next = el;
  }
#if 0  /* OLD IMPLEMENTATION */
#if defined(INTERLOGD_EMS)
  if(server_msg_is_priority(msg)) {
    /* priority messages go first */
    tail = eq->tail_ems;
    if(tail) {
      el->prev = tail->prev;
      tail->prev = el;
      if (tail == eq->tail)
	eq->tail = el;
    } else {
      el->prev = eq->head;
      eq->head = el;
      if(eq->tail == NULL)
	eq->tail = el;
    }
    eq->tail_ems = el;
  } else
#endif
  {
    /* normal messages */
    if(eq->tail)
      eq->tail->prev = el;
    else
      eq->head = el;
    eq->tail = el;
    el->prev = NULL;
  }
#if defined(INTERLOGD_EMS)
  /* if we are inserting message between mark_prev and mark_this,
     we have to adjust mark_prev accordingly */
  if(eq->mark_this && (el->prev == eq->mark_this))
    eq->mark_prev = el;
#endif
#endif /* OLD IMPLEMENTATION */

  if(++eq->cur_len > eq->max_len)
	  eq->max_len = eq->cur_len;

  el->eq = eq;

  event_queue_unlock(eq);
  /* end of critical section */

  return(0);
}