linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Jiri Olsa <jolsa@redhat.com>, LKML <linux-kernel@vger.kernel.org>,
	David Ahern <dsahern@gmail.com>
Subject: Re: [PATCH 3/7] perf tools: Move TUI-specific fields to struct hist_entry_tui
Date: Tue, 21 Apr 2015 15:34:47 +0900	[thread overview]
Message-ID: <20150421063447.GD1905@sejong> (raw)
In-Reply-To: <20150420194411.GI11111@kernel.org>

On Mon, Apr 20, 2015 at 04:44:11PM -0300, Arnaldo Carvalho de Melo wrote:
> Em Mon, Apr 20, 2015 at 10:00:46PM +0900, Namhyung Kim escreveu:
> > +++ b/tools/perf/ui/browsers/hists.c
> > @@ -61,7 +61,7 @@ static int hist_browser__get_folding(struct hist_browser *browser)
> >  			rb_entry(nd, struct hist_entry, rb_node);
>   
> >  		if (he->ms.unfolded)
> > -			unfolded_rows += he->nr_rows;
> > +			unfolded_rows += he->tui.nr_rows;
> 
> To avoid all these changes, I wonder if we can't use unamed structs in
> addition to the unnamed union?

But diff code uses named struct.  Does it support a mixed union
including named and unnamed members?

Hmm.. looks like it is.

#include <stdbool.h>
#include <stdio.h>

struct hist_entry {
	union {
		struct /* tui */ {
			int nr_rows;
			int row_offset;
			/* other fields */
		};
		struct /* diff */ {
			bool computed;
			/* other fields */
		} diff;
	};
};

int main(int argc, char *argv[])
{
	struct hist_entry he = { .nr_rows = 11, .row_offset = 19, };
	
	printf("he.nr_rows=%d, he.row_offset=%d, he.diff.computed=%d\n",
		he.nr_rows, he.row_offset, he.diff.computed);
}

namhyung@sejong:tmp$ make mixed
cc     mixed.c   -o mixed
namhyung@sejong:tmp$ ./mixed
he.nr_rows=11, he.row_offset=19, he.diff.computed=11


OK, I'll change it to unnamed struct.

Thanks,
Namhyung


> 
> Like this what is done in include/net/sock.h, struct sock_common, and
> here:
> 
> [root@zoo ~]# cat unnamed_struct_union.c 
> #include <stdbool.h>
> #include <stdio.h>
> 
> struct hist_entry {
> 	union {
> 		struct /* tui */ {
> 			int nr_rows;
> 			int row_offset;
> 			/* other fields */
> 		};
> 		struct /* diff */ {
> 			bool computed;
> 			/* other fields */
> 		};
> 	};
> };
> 
> int main(int argc, char *argv[])
> {
> 	struct hist_entry he = { .nr_rows = 11, .row_offset = 19, };
> 	
> 	printf("he.nr_rows=%d, he.row_offset=%d\n", he.nr_rows,
> he.row_offset);
> }
> [root@zoo ~]# make unnamed_struct_union
> cc     unnamed_struct_union.c   -o unnamed_struct_union
> [root@zoo ~]# ./unnamed_struct_union 
> he.nr_rows=11, he.row_offset=19
> [root@zoo ~]#
> 
> - Arnaldo
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

  reply	other threads:[~2015-04-21  6:39 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-20 13:00 [PATCHSET 0/7] perf tools: Assorted cleanup for TUI (v2) Namhyung Kim
2015-04-20 13:00 ` [PATCH 1/7] perf tools: Get rid of position field from struct hist_entry Namhyung Kim
2015-04-20 13:00 ` [PATCH 2/7] perf diff: Make hist_entry_diff fields union Namhyung Kim
2015-04-20 13:00 ` [PATCH 3/7] perf tools: Move TUI-specific fields to struct hist_entry_tui Namhyung Kim
2015-04-20 19:44   ` Arnaldo Carvalho de Melo
2015-04-21  6:34     ` Namhyung Kim [this message]
2015-04-20 13:00 ` [PATCH 4/7] perf tools: Move init_have_children field " Namhyung Kim
2015-04-20 13:00 ` [PATCH 5/7] perf hists browser: Fix possible memory leak Namhyung Kim
2015-04-20 13:00 ` [PATCH 6/7] perf hists browser: Split popup menu actions Namhyung Kim
2015-04-20 13:00 ` [PATCH 7/7] perf hists browser: Simplify zooming code a bit Namhyung Kim
  -- strict thread matches above, loose matches on Subject: below --
2015-04-19  4:04 [PATCHSET 0/7] perf tools: Assorted cleanup for TUI (v1) Namhyung Kim
2015-04-19  4:04 ` [PATCH 3/7] perf tools: Move TUI-specific fields to struct hist_entry_tui Namhyung Kim
2015-04-20  8:20   ` Jiri Olsa
2015-04-20 12:10     ` Namhyung Kim

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=20150421063447.GD1905@sejong \
    --to=namhyung@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@kernel.org \
    --cc=dsahern@gmail.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    /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).