<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Feb 15, 2017 at 1:54 PM, Chad Versace <span dir="ltr"><<a href="mailto:chadversary@chromium.org" target="_blank">chadversary@chromium.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Wed 15 Feb 2017, Emil Velikov wrote:<br>
> On 14 February 2017 at 21:02, Chad Versace <<a href="mailto:chadversary@chromium.org">chadversary@chromium.org</a>> wrote:<br>
> > On Tue 14 Feb 2017, Kenneth Graunke wrote:<br>
> >> On Tuesday, February 14, 2017 12:38:45 PM PST Chad Versace wrote:<br>
> >> > On Tue 14 Feb 2017, Matt Turner wrote:<br>
> >> ><br>
> >> ><br>
> >> > > static bool<br>
> >> > > -anv_get_function_timestamp(<wbr>void *ptr, uint32_t* timestamp)<br>
> >> > > +anv_device_get_cache_uuid(<wbr>void *uuid)<br>
> >> > > {<br>
> >> > > - Dl_info info;<br>
> >> > > - struct stat st;<br>
> >> > > - if (!dladdr(ptr, &info) || !info.dli_fname)<br>
> >> > > + const struct note *note = build_id_find_nhdr("libvulkan_<wbr>intel.so");<br>
> >> > > + if (!note)<br>
> >> > > return false;<br>
> >> > ><br>
> >> > > - if (stat(info.dli_fname, &st))<br>
> >> > > + unsigned len = build_id_length(note);<br>
> >> > > + if (len < VK_UUID_SIZE)<br>
> >> > > return false;<br>
> >> > ><br>
> >> > > - *timestamp = st.st_mtim.tv_sec;<br>
> >> > > - return true;<br>
> >> > > -}<br>
> >> > > -<br>
> >> > > -static bool<br>
> >> > > -anv_device_get_cache_uuid(<wbr>void *uuid)<br>
> >> > > -{<br>
> >> > > - uint32_t timestamp;<br>
> >> > > -<br>
> >> > > - memset(uuid, 0, VK_UUID_SIZE);<br>
> >> > > - if (!anv_get_function_timestamp(<wbr>anv_device_get_cache_uuid, ×tamp))<br>
> >> > > + unsigned char *build_id = malloc(len);<br>
> >> > > + if (!build_id)<br>
> >> > > return false;<br>
> >> > ><br>
> >> > > - snprintf(uuid, VK_UUID_SIZE, "anv-%d", timestamp);<br>
> >> > > + build_id_read(note, build_id);<br>
> >> > > +<br>
> >> > > + memcpy(uuid, build_id, VK_UUID_SIZE);<br>
> >> > > + free(build_id);<br>
> >> ><br>
> >> > The Vulkan spec frowns on memory allocations when not needed. If you<br>
> >> > must allocate memory here, then it should be through the VkInstance<br>
> >> > allocation callbacks. However, it's best to avoid the allocation by<br>
> >> > adding a size_t parameter, à la snprintf, to build_id_read().<br>
> >> ><br>
> >> > Otherwise, the patch looks good to me.<br>
> >><br>
> >> You're worried about the performance of anv_physical_device_init()?<br>
> >> This doesn't happen on lookup...just driver start up...<br>
> ><br>
> > I'm not worried about performance here. That would be foolish.<br>
> ><br>
> > I'm concerned about complying the expectations provided to advanced<br>
> > users by the Vulkan spec.<br>
<br>
> Hi Chad, pardon for dropping in uninvited:<br>
><br>
> Spec mandates that only the implementation should use the allocation<br>
> callbacks, and not any of it's dependencies (say something in the C<br>
> runtime/other library), correct ?<br>
<br>
> Or does it implicitly that "Thou Shalt override the weak<br>
> [mc]alloc/friends symbols provided by your C runtime" ?<br>
<br>
</div></div>The spec actually says neither. It is vague on this topic, but vague in<br>
a hyper-detailed fashion, which is typical of Khronos specs.<br>
<br>
I interpret "Chapter 10. Memory Allocation" as saying:<br>
<br>
- If the user supplies allocation callbacks, then the spec<br>
recommends that the implementation use them. (The spec doesn't say<br>
*should*, *suggest*, *must*, *shall*, or anything like that here,<br>
as far as I can tell. It's my interpretation that Ch10 is primarily a<br>
a recommendation.<br>
<br>
- If the implementation does use an allocation callback, Ch10<br>
defines precise constraints on how the implementation must use it.<br>
<br>
- Ch10 admits that the implementation may need to allocate internal<br>
memory, without using the callbacks. However, Ch10 seem to say<br>
that such internal allocations are soley for executable memory.<br>
Again, one could interpret the spec differently here.<br>
<span class=""><br>
> Although the src/intel is [almost] perfect, the i965 compiler still<br>
> explicitly and implicitly uses [mc]alloc. Not mean to be bashful, just<br>
> pointing out what may not be obvious at first.<br>
<br>
</span>Yep. The compiler doesn't use the allocation callbacks. For that matter,<br>
even printf calls malloc on some libc implementations.</blockquote><div><br></div><div>Yeah, I think you're worrying too much. Sure, it might be a nicer API if get_build_id did a copy into a provided array, but I wouldn't make any malloc arguments. <br></div></div><br></div></div>