qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Harsh Bora <harsh@linux.vnet.ibm.com>
To: Harsh Prateek Bora <harsh@linux.vnet.ibm.com>
Cc: stefanha@gmail.com, qemu-devel@nongnu.org, stefanha@linux.vnet.ibm.com
Subject: Re: [Qemu-devel] [PATCH v6 2/3] Simpletrace v2: Support multiple arguments, strings.
Date: Fri, 15 Jun 2012 10:52:27 +0530	[thread overview]
Message-ID: <4FDAC693.2020909@linux.vnet.ibm.com> (raw)
In-Reply-To: <1339699146-26225-3-git-send-email-harsh@linux.vnet.ibm.com>

On 06/15/2012 12:09 AM, Harsh Prateek Bora wrote:
>   static gpointer writeout_thread(gpointer opaque)
>   {
> -    TraceRecord record;
> -    unsigned int writeout_idx = 0;
> -    unsigned int num_available, idx;
> +    TraceRecord *recordptr, *dropped_ptr;
> +    union {
> +        TraceRecord rec;
> +        uint8_t bytes[sizeof(TraceRecord) + sizeof(uint64_t)];
> +    } dropped;
> +    dropped_ptr = (TraceRecord *)dropped.bytes;
> +    unsigned int idx = 0;
> +    uint64_t dropped_count;
>       size_t unused __attribute__ ((unused));
>
>       for (;;) {
>           wait_for_trace_records_available();
>
> -        num_available = trace_idx - writeout_idx;
> -        if (num_available>  TRACE_BUF_LEN) {
> -            record = (TraceRecord){
> -                .event = DROPPED_EVENT_ID,
> -                .x1 = num_available,
> -            };
> -            unused = fwrite(&record, sizeof(record), 1, trace_fp);
> -            writeout_idx += num_available;
> +        if (dropped_events) {
> +            dropped_ptr->event = DROPPED_EVENT_ID,
> +            dropped_ptr->timestamp_ns = get_clock();
> +            dropped_ptr->length = sizeof(TraceRecord) + sizeof(dropped_events),
> +            dropped_ptr->reserved = 0;
> +            while (1) {
> +                dropped_count = dropped_events;
> +                if (g_atomic_int_compare_and_exchange((gint *)&dropped_events,
> +                                                      dropped_count, 0)) {
> +                    break;
> +                }
> +            }
> +            memcpy(dropped_ptr->arguments,&dropped_count, sizeof(uint64_t));
> +            unused = fwrite(dropped_ptr, dropped_ptr->length, 1, trace_fp);
>           }
>
> -        idx = writeout_idx % TRACE_BUF_LEN;
> -        while (get_trace_record(idx,&record)) {
> -            trace_buf[idx].event = 0; /* clear valid bit */
> -            unused = fwrite(&record, sizeof(record), 1, trace_fp);
> -            idx = ++writeout_idx % TRACE_BUF_LEN;
> +        while (get_trace_record(idx,&recordptr)) {
> +            unused = fwrite(recordptr, recordptr->length, 1, trace_fp);
> +            writeout_idx += recordptr->length;
> +            g_free(recordptr);
>           }
> +        /* Note: The idx assignment expression below,
> +         * if kept in while-loop above, results in tracelog
> +         * corruption, possibly due to compiler-reordering of
> +         * statements. Keeping it out of loop saves a memory barrier.
> +         */

Hmm, I tried moving this assignment to while-loop using memory barrier 
before it, to ensure the loop can read multiple records without coming 
out of loop, however its still giving me corrupted records. However, 
keeping the assignment out of loop always works for me. Not sure what 
could be the reason for such a behaviour, above comment thus needs an 
update.

~ Harsh

> +        idx = writeout_idx % TRACE_BUF_LEN;
>
>           fflush(trace_fp);
>       }
>       return NULL;
>   }

  reply	other threads:[~2012-06-15  5:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-14 18:39 [Qemu-devel] [PATCH v6 0/3] Simpletrace v2: Support multiple args, strings Harsh Prateek Bora
2012-06-14 18:39 ` [Qemu-devel] [PATCH v6 1/3] monitor: remove unused do_info_trace Harsh Prateek Bora
2012-06-14 18:39 ` [Qemu-devel] [PATCH v6 2/3] Simpletrace v2: Support multiple arguments, strings Harsh Prateek Bora
2012-06-15  5:22   ` Harsh Bora [this message]
2012-06-14 18:39 ` [Qemu-devel] [PATCH v6 3/3] Update simpletrace.py for new log format Harsh Prateek Bora

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4FDAC693.2020909@linux.vnet.ibm.com \
    --to=harsh@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@gmail.com \
    --cc=stefanha@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).