Example #1
0
/* Create a new EventFD. */
func New() (*EventFD, error) {
	fd, err := C.eventfd(0, C.EFD_CLOEXEC)
	if err != nil {
		return nil, err
	}

	e := &EventFD{
		fd:    int(fd),
		valid: true,
	}
	return e, nil
}
Example #2
0
func NewEventFD() (*EventFD, error) {
	fd, err := C.eventfd(0, C.EFD_CLOEXEC)
	if err != nil {
		return nil, err
	}
	if fd == -1 {
		return nil, fmt.Errorf("unknown eventfd error")
	}
	efd := &EventFD{fd: int(fd)}
	runtime.SetFinalizer(efd, func(efd *EventFD) {
		efd.Close()
	})
	return efd, nil
}
Example #3
0
// NewMemCGThresholdNotifier sends notifications when a cgroup threshold
// is crossed (in either direction) for a given cgroup attribute
func NewMemCGThresholdNotifier(path, attribute, threshold, description string, handler thresholdNotifierHandlerFunc) (ThresholdNotifier, error) {
	watchfd, err := syscall.Open(fmt.Sprintf("%s/%s", path, attribute), syscall.O_RDONLY, 0)
	if err != nil {
		return nil, err
	}
	defer func() {
		if err != nil {
			syscall.Close(watchfd)
		}
	}()
	controlfd, err := syscall.Open(fmt.Sprintf("%s/cgroup.event_control", path), syscall.O_WRONLY, 0)
	if err != nil {
		return nil, err
	}
	defer func() {
		if err != nil {
			syscall.Close(controlfd)
		}
	}()
	efd, err := C.eventfd(0, C.EFD_CLOEXEC)
	if err != nil {
		return nil, err
	}
	eventfd := int(efd)
	if eventfd < 0 {
		err = fmt.Errorf("eventfd call failed")
		return nil, err
	}
	defer func() {
		if err != nil {
			syscall.Close(eventfd)
		}
	}()
	glog.V(2).Infof("eviction: setting notification threshold to %s", threshold)
	config := fmt.Sprintf("%d %d %s", eventfd, watchfd, threshold)
	_, err = syscall.Write(controlfd, []byte(config))
	if err != nil {
		return nil, err
	}
	return &memcgThresholdNotifier{
		watchfd:     watchfd,
		controlfd:   controlfd,
		eventfd:     eventfd,
		handler:     handler,
		description: description,
	}, nil
}
Example #4
0
func NewAIOScheduler(maxEvents int) (Scheduler, error) {
	fd, err := C.eventfd(0, C.EFD_NONBLOCK)
	if err != nil {
		return nil, err
	}

	eventfd, err := poller.NewFD(int(fd))
	if err != nil {
		return nil, err
	}

	sch := &aioScheduler{
		eventfd: eventfd,
		reqs:    make(map[*C.iocb_t]*event),
	}

	errno := C.io_queue_init(C.int(maxEvents), &sch.ctx)
	if errno != 0 {
		return nil, syscall.Errno(-errno)
	}

	go sch.wait_for_completions()
	return sch, nil
}