Thursday, June 12, 2014

FreeBSD and CPU scaling

Recently built a new FreeBSD machine with AMD Athlon 5350. Found that if powerd is enabled, the machine will randomly reboot itself. Forcing the lowest CPU frequency to max by setting debug.cpufreq.lowest=2050 in /boot/loader.conf can prevent that. So I suspect it is related to the CPU scaling or C-state.

This problem can be avoided if disabling the C6 state in BIOS.

For reference, the motherboard is ASRock AM1H-ITX.

Here are the CPU freq under normal powerd management.

$ sysctl dev.cpu.0.freq_levels
dev.cpu.0.freq_levels: 2050/5021 1850/4590 1650/3675 1443/3215 1400/2937 1225/2569 1200/2266 1050/1982 1000/1880 875/1645 800/1527 700/1336 600/1145 500/954 400/763 300/572 200/381 100/190


Update: 14 Jun

Found a matching bug report and reported my findings too. Basically, either C6 in BIOS or powerd in FreeBSD need to be disabled to get around the issue. Or, with C6 and powerd enable, the issue can be avoided if CPU throttling is disabled. Add this to /boot/loader.conf:

hint.acpi_throttle.0.disabled=1

But this can affect the reported lowest CPU freq.
Throttling disabled:
root@bart:~ # sysctl dev.cpu | grep freq
dev.cpu.0.freq: 800
dev.cpu.0.freq_levels: 2050/5021 1850/4590 1650/3675 1400/2937 1200/2266 1000/1880 800/1527

Saturday, May 10, 2014

When Java 8 meets Project Euler

Here is a Java implementation of a Project Euler problem. Used lambda expression and steam features of Java 8.
package net.clarenceho.euler;

import java.util.stream.IntStream;

public class Multiples3and5 {

    public static void main(String args[]) {
        System.out.println("The answer is " +
            Multiples3and5.dividableStream(1000).sum());
    }
 
    static boolean dividable(int i) {
        boolean result = false;
        if (i % 3 == 0 || i % 5 == 0) {
            result = true;
        }
        return result;
    }
 
    static IntStream dividableStream(int max) {
        return IntStream.range(1, max)
            .filter(i -> dividable(i));
    }
}

Saturday, February 15, 2014

OpenCL on UDOO

For those who interested to try OpenCL on UDOO, here is the device info

Number of platforms: 1
CL_PLATFORM_PROFILE: EMBEDDED_PROFILE
CL_PLATFORM_VERSION: OpenCL 1.1
CL_PLATFORM_VENDOR: Vivante Corporation
CL_PLATFORM_EXTENSIONS:
Number of devices: 1
CL_DEVICE_TYPE: CL_DEVICE_TYPE_GPU
CL_DEVICE_VENDOR_ID: 5654870
CL_DEVICE_MAX_COMPUTE_UNITS: 4
CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS: 3
CL_DEVICE_MAX_WORK_ITEM_SIZES: 1024 1024 1024
CL_DEVICE_MAX_WORK_GROUP_SIZE: 1024
CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR: 4
CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT: 4
CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT: 4
CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG: 0
CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT: 4
CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE: 0
CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF: 0
CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR: 4
CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT: 4
CL_DEVICE_NATIVE_VECTOR_WIDTH_INT: 4
CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG: 0
CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT: 4
CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE: 0
CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF: 0
CL_DEVICE_MAX_CLOCK_FREQUENCY: 500
CL_DEVICE_ADDRESS_BITS: 32
CL_DEVICE_MAX_MEM_ALLOC_SIZE: 33554432
CL_DEVICE_IMAGE_SUPPORT: 1
CL_DEVICE_MAX_READ_IMAGE_ARGS: 8
CL_DEVICE_MAX_WRITE_IMAGE_ARGS: 8
CL_DEVICE_IMAGE2D_MAX_WIDTH: 8192
CL_DEVICE_IMAGE2D_MAX_WIDTH: 8192
CL_DEVICE_IMAGE2D_MAX_HEIGHT: 8192
CL_DEVICE_IMAGE3D_MAX_WIDTH: 0
CL_DEVICE_IMAGE3D_MAX_HEIGHT: 0
CL_DEVICE_IMAGE3D_MAX_DEPTH: 0
CL_DEVICE_MAX_SAMPLERS: 8
CL_DEVICE_MAX_PARAMETER_SIZE: 256
CL_DEVICE_MEM_BASE_ADDR_ALIGN: 1024
CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE: 128
CL_DEVICE_SINGLE_FP_CONFIG: CL_FP_ROUND_TO_ZERO
CL_DEVICE_SINGLE_FP_CONFIG:
CL_DEVICE_GLOBAL_MEM_CACHE_TYPE: CL_READ_WRITE_CACHE
CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE: 64
CL_DEVICE_GLOBAL_MEM_CACHE_SIZE: 4096
CL_DEVICE_GLOBAL_MEM_SIZE: 67108864
CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE: 4096
CL_DEVICE_MAX_CONSTANT_ARGS: 9
CL_DEVICE_LOCAL_MEM_TYPE: CL_LOCAL | CL_GLOBAL
CL_DEVICE_LOCAL_MEM_SIZE: 1024
CL_DEVICE_ERROR_CORRECTION_SUPPORT: 1
CL_DEVICE_HOST_UNIFIED_MEMORY: 1
CL_DEVICE_PROFILING_TIMER_RESOLUTION: 1000
CL_DEVICE_ENDIAN_LITTLE: 1
CL_DEVICE_AVAILABLE: 1
CL_DEVICE_COMPILER_AVAILABLE: 1
CL_DEVICE_EXECUTION_CAPABILITIES: CL_EXEC_KERNEL
CL_DEVICE_QUEUE_PROPERTIES: CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_PROFILING_ENABLE
CL_DEVICE_PLATFORM: 0x2ace9530
CL_DEVICE_NAME: Vivante OpenCL Device
CL_DEVICE_VENDOR: Vivante Corporation
CL_DRIVER_VERSION: OpenCL 1.1
CL_DEVICE_PROFILE: EMBEDDED_PROFILE
CL_DEVICE_VERSION: OpenCL 1.1
CL_DEVICE_OPENCL_C_VERSION: OpenCL C 1.1
CL_DEVICE_EXTENSIONS: cl_khr_byte_addressable_store