<div>
                    <br>
                </div>
                <div><div><br></div><div>-- </div><div>Eli Qiao</div><div>Sent with <a href="http://www.sparrowmailapp.com/?sig">Sparrow</a></div><div><br></div></div>
                  
                <p style="color: #A0A0A8;">On Tuesday, 7 February 2017 at 12:17 AM, Daniel P. Berrange wrote:</p><blockquote type="cite"><div>
                    <span><div><div><div>On Mon, Feb 06, 2017 at 10:23:39AM +0800, Eli Qiao wrote:</div><blockquote type="cite"><div><div>virResCtrlSetCacheBanks: Set cache banks of a libvirt domain. It will</div><div>create new resource domain under `/sys/fs/resctrl` and fill the</div><div>schemata according the cache banks configration.</div><div><br></div><div>virResCtrlUpdate: Update the schemata after libvirt domain destroy.</div><div><br></div><div>Signed-off-by: Eli Qiao <<a href="mailto:liyong.qiao@intel.com">liyong.qiao@intel.com</a>></div><div>---</div><div> src/libvirt_private.syms |   2 +</div><div> src/util/virresctrl.c    | 644 ++++++++++++++++++++++++++++++++++++++++++++++-</div><div> src/util/virresctrl.h    |  47 +++-</div><div> 3 files changed, 691 insertions(+), 2 deletions(-)</div></div></blockquote><div><br></div><blockquote type="cite"><div><div>diff --git a/src/util/virresctrl.h b/src/util/virresctrl.h</div><div>index 3cc41da..11f43d8 100644</div><div>--- a/src/util/virresctrl.h</div><div>+++ b/src/util/virresctrl.h</div><div>@@ -26,6 +26,7 @@</div><div> </div><div> # include "virutil.h"</div><div> # include "virbitmap.h"</div><div>+# include "domain_conf.h"</div><div> </div><div> #define RESCTRL_DIR "/sys/fs/resctrl"</div><div> #define RESCTRL_INFO_DIR "/sys/fs/resctrl/info"</div><div>@@ -82,9 +83,53 @@ struct _virResCtrl {</div><div>         virResCacheBankPtr      cache_banks;</div><div> };</div><div> </div><div>+/**</div><div>+ * a virResSchemata represents a schemata object under a resource control</div><div>+ * domain.</div><div>+ */</div><div>+typedef struct _virResSchemataItem virResSchemataItem;</div><div>+typedef virResSchemataItem *virResSchemataItemPtr;</div><div>+struct _virResSchemataItem {</div><div>+    unsigned int socket_no;</div><div>+    unsigned schemata;</div><div>+};</div><div>+</div><div>+typedef struct _virResSchemata virResSchemata;</div><div>+typedef virResSchemata *virResSchemataPtr;</div><div>+struct _virResSchemata {</div><div>+    unsigned int n_schemata_items;</div><div>+    virResSchemataItemPtr schemata_items;</div><div>+};</div><div>+</div><div>+/**</div><div>+ * a virResDomain represents a resource control domain. It's a double linked</div><div>+ * list.</div><div>+ */</div><div>+</div><div>+typedef struct _virResDomain virResDomain;</div><div>+typedef virResDomain *virResDomainPtr;</div><div>+</div><div>+struct _virResDomain {</div><div>+    char* name;</div><div>+    virResSchemataPtr schematas[RDT_NUM_RESOURCES];</div><div>+    char* tasks;</div><div>+    int n_sockets;</div><div>+    virResDomainPtr pre;</div><div>+    virResDomainPtr next;</div><div>+};</div><div>+</div><div>+/* All resource control domains on this host*/</div><div>+</div><div>+typedef struct _virResCtrlDomain virResCtrlDomain;</div><div>+typedef virResCtrlDomain *virResCtrlDomainPtr;</div><div>+struct _virResCtrlDomain {</div><div>+    unsigned int num_domains;</div><div>+    virResDomainPtr domains;</div><div>+};</div></div></blockquote><div><br></div><div>I don't think any of these need to be in the header file - they're</div><div>all private structs used only by the .c file.</div><div><br></div></div></div></span></div></blockquote><div>Yep. </div><blockquote type="cite"><div><span><div><div><div>The biggest issue I see here is a complete lack of any kind of</div><div>mutex locking. Libvirt is multi-threaded, so you must expect to</div><div>have virResCtrlSetCacheBanks() and virResCtrlUpdate called</div><div>concurrently and thus use mutexes to ensure safety.</div><div><br></div></div></div></span></div></blockquote><div>okay. </div><blockquote type="cite"><div><span><div><div><div>With the data structure design of using linked list of virResDomain</div><div>though, doing good locking is going to be hard. It'll force you to</div><div>have a single global mutex across the whole set of data structures</div><div>which will really harm concurrency for VM startup.</div><div><br></div><div>Really each virResDomain needs to be completely standalone, with</div><div>its own dedicate mutex. A global mutex for virResCtrlDomain can</div><div>be acquired whle you lookup the virResDomain object to use. Thereafter</div><div>the global mutex should be released and only the mutex for the specific</div><div>domain used.</div></div></div></span></div></blockquote><div>oh, yes, but lock is really a hard thing, I need to be careful to avoid dead lock. </div><blockquote type="cite"><div><span><div><div><div><br></div><blockquote type="cite"><div><div> bool virResCtrlAvailable(void);</div><div> int virResCtrlInit(void);</div><div> virResCtrlPtr virResCtrlGet(int);</div><div>-</div><div>+int virResCtrlSetCacheBanks(virDomainCachetunePtr, unsigned char*, pid_t);</div><div>+int virResCtrlUpdate(void);</div></div></blockquote><div><br></div><div>This API design doesn't really make locking very easy - since you are not</div><div>passing any info into the virResCtrlUpdate() method you've created the</div><div>need to do global rescans when updating.</div></div></div></span></div></blockquote><div><br></div><div>yes, what if I use a global mutex variable in virresctrl.c?</div><blockquote type="cite"><div><span><div><div><div><br></div><div>IMHO virResCtrlSetCacheBanks needs to return an object that represents the</div><div>config for that particular VM. This can be passed back in, when the guest</div><div>is shutdown to release resources once again, avoiding any global scans.</div></div></div></span></div></blockquote><div><br></div><div>Hmm.. what object should virResCtrlSetCacheBanks return? schemata setting?</div><div>I expect that when the VM reboot, we recalculate from cachetune(in xml setting) again, that because we are not sure if the host can offer the VM for enough cache when it restart again.</div><div><br></div><div> </div><blockquote type="cite"><div><span><div><div><div><br></div><div>Regards,</div><div>Daniel</div><div>-- </div><div>|: <a href="http://berrange.com">http://berrange.com</a>      -o-    <a href="http://www.flickr.com/photos/dberrange/">http://www.flickr.com/photos/dberrange/</a> :|</div><div>|: <a href="http://libvirt.org">http://libvirt.org</a>              -o-             <a href="http://virt-manager.org">http://virt-manager.org</a> :|</div><div>|: <a href="http://entangle-photo.org">http://entangle-photo.org</a>       -o-    <a href="http://search.cpan.org/~danberr/">http://search.cpan.org/~danberr/</a> :|</div></div></div></span>
                  
                  
                  
                  
                </div></blockquote><div>
                    <br>
                </div>