From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Meng Xu <xumengpanda@gmail.com>
Cc: Ian Campbell <ian.campbell@citrix.com>,
Sisu Xi <xisisu@gmail.com>,
Stefano Stabellini <stefano.stabellini@eu.citrix.com>,
George Dunlap <george.dunlap@eu.citrix.com>,
Ian Jackson <ian.jackson@eu.citrix.com>,
"xen-devel@lists.xen.org" <xen-devel@lists.xen.org>,
Meng Xu <mengxu@cis.upenn.edu>, Jan Beulich <JBeulich@suse.com>,
Chong Li <lichong659@gmail.com>,
Dagaen Golomb <dgolomb@seas.upenn.edu>
Subject: Re: [PATCH RFC v2 1/4] xen: add real time scheduler rt
Date: Thu, 7 Aug 2014 12:48:39 +0100 [thread overview]
Message-ID: <53E36797.4080504@citrix.com> (raw)
In-Reply-To: <CAENZ-+nBBFRhqcE3Ed1dYiAHaFiZPyqudUHMxDNg4EfJMvE8eQ@mail.gmail.com>
[-- Attachment #1.1: Type: text/plain, Size: 2783 bytes --]
On 07/08/14 12:26, Meng Xu wrote:
> Hi Andrew,
>
> Thank you so much for your advice! They are very useful! :-)
>
> I have one simple question about your comments:
>
>
>>
>> > +static void *
>> > +rt_alloc_domdata(const struct scheduler *ops, struct domain *dom)
>> > +{
>> > + unsigned long flags;
>> > + struct rt_dom *sdom;
>>
>> > + struct rt_private * prv = RT_PRIV(ops);
>> > +
>> > + printtime();
>> > + printk("dom=%d\n", dom->domain_id);
>> > +
>> > + sdom = xzalloc(struct rt_dom);
>> > + if ( sdom == NULL )
>> > + {
>> > + printk("%s, xzalloc failed\n", __func__);
>> > + return NULL;
>> > + }
>> > +
>> > + INIT_LIST_HEAD(&sdom->vcpu);
>> > + INIT_LIST_HEAD(&sdom->sdom_elem);
>> > + sdom->dom = dom;
>> > +
>> > + /* spinlock here to insert the dom */
>> > + spin_lock_irqsave(&prv->lock, flags);
>> > + list_add_tail(&sdom->sdom_elem, &(prv->sdom));
>> > + spin_unlock_irqrestore(&prv->lock, flags);
>> > +
>> > + return (void *)sdom;
>>
>> Bogus cast.
>>
>>
>> I think we have to cast it to void * because the definition of
>> this function asks the return type to be void *. In addition, the
>> credit2 scheduler also did the same cast in this _alloc_domdata
>> function. So I guess this should be fine?
>>
>
> In C, all pointers are implicitly castable to/from void*. This is
> not the case in C++. (which suggests to me that George learnt C++
> before C, or is at least more familiar with C++?)
>
> The act of using type punning means that you are trying to do
> something which the C type system doesn't like. This in turn
> requires more thought from people reading the code to work out
> whether it is actually safe or not. As a result, we strive for as
> few type overrides as possible.
>
> Please don't fall into the trap of assuming the credit2 code, or
> indeed any of the other code in Xen, is perfect. None of it is,
> although most of it is good.
>
>
> I can change the return (void *)sdom to return sdom.
> But I'm not sure what else should I modify?
> In sched-if.h, this function is "void * (*alloc_domdata)
> (const struct scheduler *, struct domain *);" I think I should not
> change this declaration, otherwise, the modification will affect the
> compilation of other schedulers.
>
> Thank you so much!
>
> Best,
>
> Meng
return sdom; is perfectly fine with the existing function prototype. It
is an implicit cast of a pointer to void*, which is perfectly legal in C.
~Andrew
[-- Attachment #1.2: Type: text/html, Size: 7654 bytes --]
[-- Attachment #2: Type: text/plain, Size: 126 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
next prev parent reply other threads:[~2014-08-07 11:48 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-29 1:52 Introduce rt real-time scheduler for Xen Meng Xu
2014-07-29 1:52 ` [PATCH RFC v2 1/4] xen: add real time scheduler rt Meng Xu
2014-07-29 6:52 ` Jan Beulich
2014-07-29 9:42 ` Dario Faggioli
2014-07-30 15:55 ` [RFC " Meng Xu
2014-07-29 10:36 ` [PATCH RFC " Andrew Cooper
2014-08-02 15:31 ` Meng Xu
2014-08-04 10:23 ` Andrew Cooper
2014-08-07 11:26 ` Meng Xu
2014-08-07 11:48 ` Andrew Cooper [this message]
2014-07-29 1:53 ` [PATCH RFC v2 2/4] libxc: add rt scheduler Meng Xu
2014-07-29 1:53 ` [PATCH RFC v2 3/4] libxl: " Meng Xu
2014-07-29 1:53 ` [PATCH RFC v2 4/4] xl: introduce " Meng Xu
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=53E36797.4080504@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=JBeulich@suse.com \
--cc=dgolomb@seas.upenn.edu \
--cc=george.dunlap@eu.citrix.com \
--cc=ian.campbell@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=lichong659@gmail.com \
--cc=mengxu@cis.upenn.edu \
--cc=stefano.stabellini@eu.citrix.com \
--cc=xen-devel@lists.xen.org \
--cc=xisisu@gmail.com \
--cc=xumengpanda@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.