ItFor real functions whose domain is a real interval, it is necessary and sufficient that the second derivative is a function of bounded variation on every compact interval in the domain. Or, in terms of distributions, the second derivative must be a measure (a difference of two non-negative measures).