Exemple #1
0
static int is_softlockup(unsigned long touch_ts)
{
	unsigned long now = get_timestamp(smp_processor_id());

	/* Warn about unreasonable delays: */
	if (time_after(now, touch_ts + softlockup_thresh))
		return now - touch_ts;

	return 0;
}
static void data_bridge_read_cb(struct urb *urb)
{
	struct bridge		*brdg;
	struct sk_buff		*skb = urb->context;
	struct timestamp_info	*info = (struct timestamp_info *)skb->cb;
	struct data_bridge	*dev = info->dev;
	bool			queue = 0;

	brdg = dev->brdg;
	skb_put(skb, urb->actual_length);

	switch (urb->status) {
	case -ENOENT: /* suspended */
	case 0: /* success */
		queue = 1;
		info->rx_done = get_timestamp();
		spin_lock(&dev->rx_done.lock);
		__skb_queue_tail(&dev->rx_done, skb);
		spin_unlock(&dev->rx_done.lock);
		break;

	/*do not resubmit*/
	case -EPIPE:
		set_bit(RX_HALT, &dev->flags);
		dev_err(&dev->udev->dev, "%s: epout halted\n", __func__);
		schedule_work(&dev->kevent);
		/* FALLTHROUGH */
	case -ESHUTDOWN:
	case -ECONNRESET: /* unplug */
	case -EPROTO:
		dev_kfree_skb_any(skb);
		break;

	/*resubmit */
	case -EOVERFLOW: /*babble error*/
	default:
		queue = 1;
		dev_kfree_skb_any(skb);
		pr_debug_ratelimited("%s: non zero urb status = %d\n",
			__func__, urb->status);
		break;
	}

	spin_lock(&dev->rx_done.lock);
	urb->context = NULL;
	list_add_tail(&urb->urb_list, &dev->rx_idle);
	spin_unlock(&dev->rx_done.lock);

	/* during suspend handle rx packet, but do not queue rx work */
	if (urb->status == -ENOENT)
		return;

	if (queue)
		queue_work(dev->wq, &dev->process_rx_w);
}
bool network_process_recvq(network_t * network)
{
    probe_t       * probe,
                  * reply;
    packet_t      * packet;
    probe_reply_t * probe_reply;

    // Pop the packet from the queue
    if (!(packet = queue_pop_element(network->recvq, NULL))) {
        goto ERR_PACKET_POP;
    }

    // Transform the reply into a probe_t instance
    if(!(reply = probe_wrap_packet(packet))) {
        goto ERR_PROBE_WRAP_PACKET;
    }
    probe_set_recv_time(reply, get_timestamp());

    if (network->is_verbose) {
        printf("Got reply:\n");
        probe_dump(reply);
    }

    // Find the probe corresponding to this reply
    // The corresponding pointer (if any) is removed from network->probes
    if (!(probe = network_get_matching_probe(network, reply))) {
        goto ERR_PROBE_DISCARDED;
    }

    // Build a pair made of the probe and its corresponding reply
    if (!(probe_reply = probe_reply_create())) {
        goto ERR_PROBE_REPLY_CREATE;
    }

    // We're pass to the upper layer the probe and the reply to the upper layer.
    probe_reply_set_probe(probe_reply, probe);
    probe_reply_set_reply(probe_reply, reply);

    // Notify the instance which has build the probe that we've got the corresponding reply

    // TODO this provokes a double free:
    //pt_throw(NULL, probe->caller, event_create(PROBE_REPLY, probe_reply, NULL, (ELEMENT_FREE) probe_reply_free));
    pt_throw(NULL, probe->caller, event_create(PROBE_REPLY, probe_reply, NULL, NULL));

    // TODO probe_reply_free frees only the reply but probe_reply_deep_free cannot be used as other things may have references to its contents.
    return true;

ERR_PROBE_REPLY_CREATE:
ERR_PROBE_DISCARDED:
    probe_free(reply);
ERR_PROBE_WRAP_PACKET:
    //packet_free(packet); TODO provoke segfault in case of stars
ERR_PACKET_POP:
    return false;
}
Exemple #4
0
int main() {

    printf("Answer: %lu\n", solution());

    timestamp_t t0 = get_timestamp();

    for (int i = 0; i < 3; ++i) {
        solution();
    }

    timestamp_t t1 = get_timestamp();

    double t_elapsed = (t1 - t0) / 1000000.0L / 3;

    if (t_elapsed < 3) {
         int run_time = 10;
         unsigned long long n_iters = run_time / t_elapsed;

         timestamp_t t0 = get_timestamp();

         for (int i = 0; i < n_iters; ++i) {
             solution();
         }

         timestamp_t t1 = get_timestamp();
         t_elapsed = (t1 - t0) / 1000000.0L / n_iters;
    }

    double exp_t = log10(t_elapsed);

    if (exp_t > 0) {
        printf("Average Duration: %.3g s\n", t_elapsed);
    } else if (exp_t > -3) {
        printf("Average Duration: %.3Lg ms\n", t_elapsed * 1000.0L);
    } else if (exp_t > -6) {
        printf("Average Duration: %.3Lg µs\n", t_elapsed * 1000000.0L);
    } else {
        printf("Average Duration: %.3Lg ns\n", t_elapsed * 1000000000.0L);
    }

    return 0;
}
static void data_bridge_read_cb(struct urb *urb)
{
	struct bridge		*brdg;
	struct sk_buff		*skb = urb->context;
	struct timestamp_info	*info = (struct timestamp_info *)skb->cb;
	struct data_bridge	*dev = info->dev;
	bool			queue = 0;

	
	if (urb->dev->state == USB_STATE_NOTATTACHED)
		urb->status = -ECONNRESET;

	brdg = dev->brdg;
	skb_put(skb, urb->actual_length);

	switch (urb->status) {
	case 0: 
		queue = 1;
		info->rx_done = get_timestamp();
		spin_lock(&dev->rx_done.lock);
		__skb_queue_tail(&dev->rx_done, skb);
		spin_unlock(&dev->rx_done.lock);
		break;

	
	case -EPIPE:
		set_bit(RX_HALT, &dev->flags);
		dev_err(&dev->intf->dev, "%s: epout halted\n", __func__);
		schedule_work(&dev->kevent);
		
	case -ESHUTDOWN:
	case -ENOENT: 
	case -ECONNRESET: 
	case -EPROTO:
		dev_kfree_skb_any(skb);
		break;

	
	case -EOVERFLOW: 
	default:
		queue = 1;
		dev_kfree_skb_any(skb);
		pr_debug_ratelimited("%s: non zero urb status = %d\n",
			__func__, urb->status);
		break;
	}

	spin_lock(&dev->rx_done.lock);
	list_add_tail(&urb->urb_list, &dev->rx_idle);
	spin_unlock(&dev->rx_done.lock);

	if (queue)
		queue_work(dev->wq, &dev->process_rx_w);
}
Exemple #6
0
static void print_stats(void)
{
	unsigned long long delay = get_timestamp() - start_stamp;

	if (!delay)
		delay = 1;

	pr_warn("TX: %llu bytes (%llu bps), RX: %llu bytes (%llu bps)\n",
		tx_bytes, tx_bytes * 8000000 / delay, rx_bytes,
		rx_bytes * 8000000 / delay);
}
Exemple #7
0
static int is_softlockup(unsigned long touch_ts)
{
	unsigned long now = get_timestamp();

	if ((watchdog_enabled & SOFT_WATCHDOG_ENABLED) && watchdog_thresh){
		/* Warn about unreasonable delays. */
		if (time_after(now, touch_ts + get_softlockup_thresh()))
			return now - touch_ts;
	}
	return 0;
}
void
nest::Stopwatch::stop()
{
#ifdef ENABLE_TIMING
    if(isRunning())
    {
        _end = get_timestamp(); // invariant: _end >= _beg
        _running = false;       // we stopped running
    }
#endif
}
static void data_bridge_process_rx(struct work_struct *work)
{
	int			retval;
	unsigned long		flags;
	struct urb		*rx_idle;
	struct sk_buff		*skb;
	struct timestamp_info	*info;
	struct data_bridge	*dev =
		container_of(work, struct data_bridge, process_rx_w);

	struct bridge		*brdg = dev->brdg;

// ASUS_BSP+++ Wenli "tty device for AT command"
#ifndef DISABLE_ASUS_DUN
	if (is_open_asus) {
		data_bridge_process_rx_asus(work);
		return;
	}
#endif
// ASUS_BSP--- Wenli "tty device for AT command"
	if (!brdg || !brdg->ops.send_pkt || rx_halted(dev) || !is_open_usb)
		return;

	while (!rx_throttled(brdg) && (skb = skb_dequeue(&dev->rx_done))) {
		dev->to_host++;
		info = (struct timestamp_info *)skb->cb;
		info->rx_done_sent = get_timestamp();
		/* hand off sk_buff to client,they'll need to free it */
		retval = brdg->ops.send_pkt(brdg->ctx, skb, skb->len);
		if (retval == -ENOTCONN || retval == -EINVAL) {
			return;
		} else if (retval == -EBUSY) {
			dev->rx_throttled_cnt++;
			break;
		}
	}

	spin_lock_irqsave(&dev->rx_done.lock, flags);
	while (!list_empty(&dev->rx_idle)) {
		if (dev->rx_done.qlen > stop_submit_urb_limit)
			break;

		rx_idle = list_first_entry(&dev->rx_idle, struct urb, urb_list);
		list_del(&rx_idle->urb_list);
		spin_unlock_irqrestore(&dev->rx_done.lock, flags);
		retval = submit_rx_urb(dev, rx_idle, GFP_KERNEL);
		spin_lock_irqsave(&dev->rx_done.lock, flags);
		if (retval) {
			list_add_tail(&rx_idle->urb_list, &dev->rx_idle);
			break;
		}
	}
	spin_unlock_irqrestore(&dev->rx_done.lock, flags);
}
void 
nest::Stopwatch::pause()
{
#ifdef ENABLE_TIMING
  if(isRunning())
    {
        _end = get_timestamp(); 
        _running = false;               // we stop running
    }
#endif 
}
void debug_fl(char *msg, char *file, int line)
{
	char *timestamp;
	timestamp = get_timestamp();
	fprintf(stdout,"[DEBUG][%s] (%s:%d) %s [pid=%d]\n",
		timestamp, __FILE__, __LINE__, msg, getpid());
	fflush(stdout);
	if (timestamp != NULL) {
		free(timestamp);
		timestamp = NULL;
	}
}
/**
 *	locking_finalize: - finalize last buffer at end of channel use
 *	@rchan: the channel
 */
inline void
locking_finalize(struct rchan *rchan)
{
    unsigned long int flags;
    struct timeval time;
    u32 tsc;

    local_irq_save(flags);
    get_timestamp(&time, &tsc, rchan);
    switch_buffers(time, tsc, rchan, 1, 0, 0);
    local_irq_restore(flags);
}
void
nest::Stopwatch::start()
{
#ifdef ENABLE_TIMING
    if(!isRunning())
    {
        _prev_elapsed += _end - _beg;  // store prev. time, if we resume
        _end = _beg = get_timestamp(); // invariant: _end >= _beg
        _running = true;               // we start running
    }
#endif
}
Exemple #14
0
static gchar *
get_nonce (void)
{
  gchar *timestamp = get_timestamp();
  guint rnd_number = g_random_int ();
  gchar *rnd_str = g_strdup_printf ("%d_%s", rnd_number, timestamp);
  gchar *nonce = g_compute_checksum_for_string (G_CHECKSUM_MD5, rnd_str, -1);
  g_free (timestamp);
  g_free (rnd_str);

  return nonce;
}
Exemple #15
0
void
gettime(char *unused)
{
  uint32_t actticks;
  get_timestamp(&actticks);
  uint8_t *p = (uint8_t *)&actticks;
  DH2(p[3]);
  DH2(p[2]);
  DH2(p[1]);
  DH2(p[0]);
  DNL();
}
/* This handles Digest Authentication. Returns a hash of the 
   User, Realm and (Required) Password. Caller (Digest module)
	 determines if the entered password was actually valid
*/
static authn_status ga_get_realm_hash(request_rec *r, const char *user,
                                   const char *realm, char **rethash)
{
	/* Per Apache mod_auth.h:
	*  Given a user and realm, expected to return AUTH_USER_FOUND if we
	*  can find a md5 hash of 'user:realm:password'
	*/
    authn_google_config_rec *conf = ap_get_module_config(r->per_dir_config,
                                                       &authn_google_module);
		char *sharedKey;
		char *ga_filename;
		char *static_pw;

if (conf->debugLevel)
    ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
      "**** DIGEST AUTH at  T=%lu  user  \"%s\"",apr_time_now()/1000000,user);


		unsigned char *hash = apr_palloc(r->pool,APR_MD5_DIGESTSIZE);


		ga_filename = apr_psprintf(r->pool,"%s/%s",conf->pwfile,user);

    ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
"GetRealmHash called for sharedkey \"%s\"\n",ga_filename);
		sharedKey = getSharedKey(r,ga_filename,&static_pw);

		if (!sharedKey)
        return AUTH_USER_NOT_FOUND;

		int secretLen;
		uint8_t *secret = get_shared_secret(r,sharedKey,&secretLen);

		unsigned int truncatedHash = computeTimeCode(get_timestamp(),secret,secretLen);
		char *pwstr;
		if (static_pw) {
			pwstr = apr_psprintf(r->pool,"%s%6.6u",static_pw,truncatedHash);
		}
		else 
		{
			pwstr = apr_psprintf(r->pool,"%6.6u",truncatedHash);
		}
		char *hashstr = apr_psprintf(r->pool,"%s:%s:%s",user,realm,pwstr);

if (conf->debugLevel)
    ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
      "Password \"%s\" at modulus %lu",pwstr,(apr_time_now() / 1000000) % 30);

		apr_md5(hash ,hashstr,strlen(hashstr));
		*rethash = hex_encode(r->pool,hash,APR_MD5_DIGESTSIZE);
		addCookie(r,secret,secretLen);
    return AUTH_USER_FOUND;
}
//******************************************************************************
int check_timeranges_list(struct tm *event_time, timerange_t *list){
	timerange_t *curr;
	if(!list) return 0;
	int tm = get_timestamp(event_time);
	if(debug) fprintf(stdout, "Current timestamp: %i\n", tm);
	for(curr = list; curr!=NULL; curr = curr->next){
		if(curr->from <= tm && tm <= curr->to){
			return 1;
		}
	}
	return 0;
}
Exemple #18
0
// Experiment(): runs a timing experiment for all 
//               the algorithms added to the experiment.
//
//   - Run sorts on array sizes of 1000 to 100000
//   - The timing results are stored in the 2D array timings[alg #][size]
// ------------------------------------------------------------------------
void Experiment::run() {
    timestamp_t startTime;		// start time
    timestamp_t endTime;		// end time
    
    cout << "\nRunning timing experiments on arrays of size 1K to 25K\n" << endl;

    // Allocate storage for the timing output and problem size
    timings = new double* [algorithm.size()];
    for (int i = 0; i < algorithm.size(); i++) {
        timings[i] = new double[25];
    }

    // Run each algorithm in sequence
    for( int k=0; k<algorithm.size(); k++ ){
        int N = 0;
        for( int run=0; run<repetitions; run++ ){
            // increase the number of values to sort by increments of 1000
            N = N + 1000;

	    data->refresh();
		    
	    // Time the sorting algorithm 
	    startTime = get_timestamp();	  // start the timer
             
            // sort on Name and then Zip
	    (algorithm[k])->sort(data, N, Contact::compareName);
	    (algorithm[k])->sort(data, N, Contact::compareZip);

            endTime = get_timestamp();	  // stop the timer

            // verify results by printing first 10 contacts
            cout << "\nFirst 10 records after sorting\n"; 
            data->print(0,10);
            
	    // Average number of elapsed seconds over the trials
            timings[k][run] = (endTime - startTime) / 1000000.0L;
            cout << "Sorted " << N << " records using algorithm [" << k << "]" << endl;
	}
    }
}
    void
    log ( char const * format, ... )
    {
      FILE * fp = output_fp ? output_fp : stdout;

      va_list ap;
      fprintf ( fp, "%.4lf ", get_timestamp() );
      va_start(ap, format);
      vfprintf ( fp, format, ap );
      va_end(ap);
      fputc ( '\n', fp );
      fflush  ( fp );
    }
Exemple #20
0
static inline void do_exec_command(struct service_processor *sp)
{
	char tsbuf[32];

	dbg("%s:%d at %s\n", __FUNCTION__, __LINE__, get_timestamp(tsbuf));

	if (ibmasm_send_i2o_message(sp)) {
		sp->current_command->status = IBMASM_CMD_FAILED;
		wake_up(&sp->current_command->wait);
		command_put(sp->current_command);
		exec_next_command(sp);
	}
}
Exemple #21
0
void
 get_YYYY (char *year)
{

struct tm *result;
time_t now;

setenv("TZ", "UTC", 0);
now = get_timestamp();
result = gmtime(&now);

sprintf(year, "%d", 1900+result->tm_year);
}
Exemple #22
0
//
// We'll write to STDERR instead since the user doesn't want to see
// any error popups.  Add a timestamp to the front so we know when
// the errors happened.
//
void popup_message(char *banner, char *message) {
    char timestring[110];


    if (disable_all_popups)
        return;

    if (banner == NULL || message == NULL)
        return;

    get_timestamp(timestring);
    fprintf(stderr, "%s:\n\t%s  %s\n\n", timestring, banner, message);
}
Exemple #23
0
user_opt user_opt_init(char *api_key, char *api_secret)
{
	user_opt user_info;
	char * uuid;
	strcpy(user_info.api_key, api_key);
	strcpy(user_info.api_secret, api_secret);
	get_timestamp(user_info.timestamp);
	uuid = get_uuid();
	strcpy(user_info.salt, uuid);
	get_signature(user_info.timestamp, user_info.salt, user_info.api_secret, user_info.signature);
	free(uuid);
	return user_info;
}
Exemple #24
0
static int submit_rx_urb(struct data_bridge *dev, struct urb *rx_urb,
	gfp_t flags)
{
	struct sk_buff		*skb;
	struct timestamp_info	*info;
	int			retval = -EINVAL;
	unsigned int		created;

	created = get_timestamp();
	skb = alloc_skb(RMNET_RX_BUFSIZE, flags);
	if (!skb)
		return -ENOMEM;

	info = (struct timestamp_info *)skb->cb;
	info->dev = dev;
	info->created = created;

	usb_fill_bulk_urb(rx_urb, dev->udev, dev->bulk_in,
			  skb->data, RMNET_RX_BUFSIZE,
			  data_bridge_read_cb, skb);

	if (test_bit(SUSPENDED, &dev->flags))
		goto suspended;

	usb_anchor_urb(rx_urb, &dev->rx_active);
	info->rx_queued = get_timestamp();
	retval = usb_submit_urb(rx_urb, flags);
	if (retval)
		goto fail;

	usb_mark_last_busy(dev->udev);
	return 0;
fail:
	usb_unanchor_urb(rx_urb);
suspended:
	dev_kfree_skb_any(skb);

	return retval;
}
Exemple #25
0
static int get_time_stamp(unsigned long long * ts)
{
	unsigned long long timestamp;

	timestamp = get_timestamp();

	if (copy_to_user(ts, &timestamp, sizeof(unsigned long long)) != 0)
	{
		return -EFAULT;
	}

	return 0;
}
Exemple #26
0
static void *receive_start(void *arg)
{
	int fd = (unsigned long)arg;
	struct msg *msg;
	ssize_t res;
	unsigned int avail = 0;
	static unsigned char buf[MAX_MAX_MSG_LEN];
	unsigned long long delay;

	while (1) {
		msg = opt_master ? msg_get() : msg_gen(-opt_msglen);

		while (avail < msg->len) {
			res = read(fd, buf + avail, sizeof(buf) - avail);
			if (res < 0) {
				pr_error("Read error %d\n", errno);
				exit(-1);
			}
			avail += res;
			rx_bytes += res;
		}

		if (!msg_verify(msg, buf)) {
			pr_error("Data mismatch\n");
			cmp_buffer(buf, msg->buf, msg->len);
			print_stats();
			exit(-1);
		}

		delay = get_timestamp() - msg->stamp;
		if (!delay)
			delay = 1;
		pr_debug(ESC_GREEN "OK %u bytes in %llu us (%llu bps)\n",
			msg->len, delay, msg->len * 8000000 / delay);

		avail -= msg->len;
		if (avail > 0) {
			pr_debug("Keeping %u bytes\n", avail);
			memmove(buf, buf + msg->len, avail);
		}

		if (!opt_master && opt_chain) {
			msg_inc(msg);
			msg_add(msg);
		} else {
			free(msg);
		}
	}

	return NULL;
}
int main(int narg, char* argc[])
{
    std::cout.setf( std::ios::fixed, std:: ios::floatfield );
    std::cout.precision(8);
    
    double infIntegral, supIntegral, midIntegral;
    
    timestamp_t inicio, fim;
	inicio = get_timestamp();
	
		std::vector<Function*> functions;
	
		functions.push_back( new Function1() );
		functions.push_back( new Function2() );

		GaussianQuadrature quadrature(argc[1], functions);
		midIntegral = quadrature.calculateIntegral();

		std::cout << "Quad: " << midIntegral << '\n';

		ClosedNewtonCotes infTrapezio(argc[2], 1);
		infIntegral = infTrapezio.calculateIntegral();
	
		std::cout << "Inf: " << infIntegral << '\n';
	
		ClosedNewtonCotes supTrapezio(argc[3], 1);
		supIntegral = supTrapezio.calculateIntegral();

		std::cout << "Sup: " << supIntegral << '\n';
	
		std::cout << "Integral: " << infIntegral + midIntegral + supIntegral << "\n";

    fim = get_timestamp();	
	
	std::cout << "tempo: " << (fim - inicio)/1000.0L << " milissegundos.\n";

	return 0;
}
//===========================
//		Scheduler
//===========================
int schedule(Whiteboard& wb, std::vector<AlgoBase*>& chain, unsigned int events, unsigned int n_parallel) {
    
    // time it
    timestamp_t tstart = get_timestamp();
    
    // set up the scheduler
    EventLoopManager manager(chain, wb, n_parallel);
    manager.run(events);

    tbb::spin_mutex::scoped_lock lock;
    
    // wait for all jobs completing
    lock.acquire(my_mutex);
    printf("\nWaiting for all completing\n");
    lock.release();
    
    // time it
    timestamp_t tstop = get_timestamp();
    timestamp_t totTime = tstop-tstart;
    printf("elapsed time:\t %llu \n", totTime);
    printf("time/event:\t\t %llu\n",totTime/events);
    return totTime;
}
Exemple #29
0
			/// Streams the current timestamp and the "AMPTEST:" line prefix.
			static inline void stream_line_prefix(std::ostream& log_stream, LogType type) {
				if(type == LogType::Silent) return;

				// Compose the prefix as a string so it won't get broken up
				std::stringstream ss;
				ss << get_timestamp() << " AMPTest: ";
				if(type == LogType::Warning) {
					ss << "Warning: ";
				} else if(type == LogType::Error) {
					ss << "Error: ";
				}

				log_stream << ss.str();
			}
int main(int narg, char* argc[])
{
    std::cout.setf( std::ios::fixed, std:: ios::floatfield );
    std::cout.precision(8);
    
    timestamp_t inicio, fim;
	inicio = get_timestamp();
	
		std::vector<Function*> functions;
	
		functions.push_back( new Function1() );
		functions.push_back( new Function2() );

		RombergIntegration romberg(argc[1], functions, atoi(argc[2]));

		std::cout << "Integral: " << romberg.calculateIntegral() << "\n";

    fim = get_timestamp();	
	
	std::cout << "tempo: " << (fim - inicio)/1000.0L << " milissegundos.\n";

	return 0;
}