On Thu, Dec 24, 2009 at 11:45:51PM +0530, Poornima Nayak wrote:
> +def get_hyper_thread_count():
> +    ''' Return number of threads in cpu0
> +    '''
> +    try:
> +        file_cpuinfo = 
> open("/sys/devices/system/cpu/cpu0/topology/thread_siblings", 'r')
> +        threads_count = 0
> +        for line in file_cpuinfo:
> +            core_grps = line.split(",")
> +            for i in range(0, len(core_grps)):
> +                cpumask=int(core_grps[i])
> +                while cpumask > 0:
> +                    threads_count = threads_count + 1
> +                    cpumask = cpumask >> 1
> +        return threads_count
> +    except Exception, details:
> +        print "INFO: Failed to get threaded siblings count", details
> +        sys.exit(1)
> +
> +def get_core_sibling_count():
> +    ''' Return number of threads in cpu0
> +    '''
> +    try:
> +        file_cpuinfo = 
> open("/sys/devices/system/cpu/cpu0/topology/core_siblings", 'r')
> +        cores_count = 0
> +        for line in file_cpuinfo:
> +            core_grps = line.split(",")
> +            for i in range(0, len(core_grps)):
> +                cpumask=int(core_grps[i])
> +                while cpumask > 0:
> +                    cores_count = cores_count + 1
> +                    cpumask = cpumask >> 1
> +        return cores_count
> +    except Exception, details:
> +        print "INFO: Failed to get core siblings count", details
> +        sys.exit(1)
> +

We could avoid the code repetition above.

def get_entity_count(entity):
        try:
                file_cpuinfo =
                open("/sys/devices/system/cpu/cpu0/topology/" + entity + 
"siblings", 'r)
                .
                .
                .
        except
                .
                .
                .

def get_hyper_thread_count():
        return get_entity_count("thread")

def get_core_sibling_count():
        return get_entity_count("core")



-- 
Thanks and Regards
gautham

------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to